'''
Created on Apr 10, 2013

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