default value for django choice field

前端 未结 2 1295
天涯浪人
天涯浪人 2020-12-17 17:43

Suppose class Photo is to hold photos having choice fields and other attributes:

class Photo(models.Model):
    ONLYME = \'O\'
    FRIENDS =         


        
2条回答
  •  情话喂你
    2020-12-17 18:32

    You could just set the default attribute:

    display = models.CharField(default='F', max_length=1, choices=CHOICES, blank=True, null=True)
    

    Reference.

提交回复
热议问题