[Fixed]-Convert the choice value by transforming the model to json format

1👍

class Cargo(models.Model): 
    nombre = models.CharField(max_length=50,verbose_name='Nombre',unique=True) 
    descripcion = models.CharField(max_length=100,verbose_name='Descripcion', blank=True) 
    estado = models.IntegerField(choices=ESTADO,default=1, verbose_name='Estado')

    def __unicode__(self):
        return '%s - %s'%(self.nombre,self.get_estado_display())

    class Meta:
        verbose_name = 'Cargo'
        verbose_name_plural = 'Cargos'
        ordering = ['-nombre']

    @property
    def get_estado(self):
        return self.get_estado_display()

and then use model_obj.get_estado rather than model_obj.estado in your serializer definition.

you might have to use Django Rest Framework to do this successfully. If so see this question https://stackoverflow.com/a/28954424/331974

👤BenDog

Leave a comment