'''
Created on Apr 10, 2013

@author: egiraldo
'''
from django.forms import widgets
from rest_framework import serializers
from actividades.models import Actividad
class ActividadSerializer(serializers.Serializer):
    pk = 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)
    programa = serializers.CharField(widget=widgets.Textarea,max_length=200)
    def restore_object(self, attrs, instance=None):
        if instance:
            # Update existing instance
            instance.nombre = attrs.get('nombre', instance.title)
            instance.descripcion = attrs.get('descripcion', instance.code)
            instance.programa = attrs.get('programa', instance.language)
            return instance
        # Create new instance
        return Actividad(**attrs)
