'''
Created on Apr 10, 2013

@author: egiraldo
'''
from django.forms import widgets
from rest_framework import serializers
from modulos.models import Modulo
class ModuloSerializer(serializers.Serializer):
    id_modulo = serializers.Field()  # Note: `Field` is an untyped read-only field.
    id_conexion = serializers.Field()  # Note: `Field` is an untyped read-only field.
    nombre = 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_conexion = attrs.get('id_conexion', instance.id_conexion)
            instance.nombre = attrs.get('nombre', instance.nombre)
            instance.descripcion = attrs.get('descripcion', instance.descripcion)
            return instance
        # Create new instance
        return Modulo(**attrs)
