'''
Created on Apr 10, 2013

@author: egiraldo
'''
from django.forms import widgets
from rest_framework import serializers
from grupos.models import Grupo
class GrupoSerializer(serializers.Serializer):
    id_grupo = serializers.Field()  # Note: `Field` is an untyped read-only field.
    id_tabla = serializers.Field()  # Note: `Field` is an untyped read-only field.
    nombre = serializers.CharField(widget=widgets.Textarea,max_length=200)
    tabla = serializers.CharField(widget=widgets.Textarea,max_length=200)
    campo = serializers.CharField(widget=widgets.Textarea,max_length=200)
    descripcion = serializers.CharField(widget=widgets.Textarea,max_length=200)
    def restore_object(self, attrs, instance=None):
        if instance:
            # Update existing instance
            instance.id_tabla = attrs.get('id_tabla', instance.id_tabla)
            instance.nombre = attrs.get('nombre', instance.nombre)
            instance.tabla = attrs.get('tabla', instance.tabla)
            instance.campo = attrs.get('campo', instance.campo)
            instance.descripcion = attrs.get('descripcion', instance.descripcion)
            return instance
        # Create new instance
        return Grupo(**attrs)
