Django Rest Framework: estado is an invalid keyword argument for this function Django Rest Framework: 'estado'是此函数的无效关键字参数

2024-05-19 08:37:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是DRF,我得到了这个带有嵌套序列化的TypeError。我读了Documentation,但我还是不能解决我的问题。在

型号:

class Estado(models.Model): 
    estado = models.CharField(max_length=100, blank=True)

    def __unicode__(self):
        return self.estado

class Municipio(models.Model):
    estado = models.ForeignKey(Estado)
    municipio = models.CharField(max_length=100, blank=True)

    def __unicode__(self):
        return self.municipio

class Usuario(models.Model):    
    user = models.OneToOneField(User)
    estado = models.ForeignKey(Estado)
    municipio = models.ForeignKey(Municipio) 
    donador = models.BooleanField(default=False)

    def __unicode__(self):
        return self.user.username

序列化程序:

^{pr2}$

我正在尝试创建一个“usario”模型,它是用户的配置文件。在


Tags: selfmodelreturn序列化modelsdefunicodelength

热门问题