'''
Created on Apr 10, 2013

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