Django Model Choices

后端 未结 1 900
悲哀的现实
悲哀的现实 2021-01-03 00:39

I\'ve been stumped by how to make choices within my models for hours.

So far I\'ve been having issues with my approved field in the model. I want approved to be 1 of

1条回答
  •  时光说笑
    2021-01-03 01:16

    approved as you have it isn't a field, it's simply a class attribute containing the three choices. The choices need to be an attribute of an actual field:

    APPROVAL_CHOICES = (
        (u'1', u'Awaiting'),
        (u'2', u'No'),
        (u'3', u'Yes'),
    )
    approved = models.CharField(max_length=1, choices=APPROVAL_CHOICES)
    

    0 讨论(0)
提交回复
热议问题