'''
Created on Apr 9, 2014

@author: egiraldo
'''
from django.forms import widgets
from rest_framework import serializers
from formula.models import Formula
class FormulaSerializer(serializers.Serializer):
	id_formulas= serializers.Field()  # Note: `Field` is an untyped read-only field.
	id_modulo = serializers.Field()  # Note: `Field` is an untyped read-only field.
	id_transaccion= serializers.Field()  # Note: `Field` is an untyped read-only field.
	nombre_formula = serializers.CharField(widget=widgets.Textarea,max_length=200)
	formula = serializers.CharField(widget=widgets.Textarea,max_length=2000)
	tablas_asociadas = serializers.CharField(widget=widgets.Textarea,max_length=200)
	usa_tablas = serializers.IntegerField(widget=widgets.Textarea,max_length=1)
	def restore_object(self, attrs, instance=None):
		if instance:
			# Update existing instance
			instance.id_formulas = attrs.get('id_formulas', instance.id_formulas)
			instance.id_modulo = attrs.get('id_modulo', instance.id_modulo)
			instance.id_transaccion = attrs.get('id_transaccion', instance.id_transaccion)
			instance.nombre_formula = attrs.get('nombre_formula', instance.nombre_formula)
			instance.formula = attrs.get('formula', instance.formula)
			instance.tablas_asociadas = attrs.get('tablas_asociadas', instance.tablas_asociadas)
			instance.usa_tablas = attrs.get('usa_tablas', instance.usa_tablas)
		# Create new instance
        return Formula(**attrs)