'''
Created on Apr 9, 2014

@author: egiraldo
'''
from django.forms import widgets
from rest_framework import serializers
from constante.models import Constante
class ConstanteSerializer(serializers.Serializer):
	id_constante=serializers.Field()  # Note: `Field` is an untyped read-only field.
	nombre_constante= serializers.CharField(widget=widgets.Textarea,max_length=200)
	valor_constante = serializers.CharField(widget=widgets.Textarea,max_length=200)
	def restore_object(self, attrs, instance=None):
		if instance:
			# Update existing instance
			instance.id_constante = attrs.get('id_constante', instance.id_constante)
			instance.nombre_constante = attrs.get('nombre_constante', instance.nombre_constante)
			instance.valor_constante = attrs.get('valor_constante', instance.valor_constante)
		# Create new instance
        return Constante(**attrs)