default value for django choice field

前端 未结 2 1290
天涯浪人
天涯浪人 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:47

    Use the default attribute:

    display = models.CharField(..., default=FRIENDS)
    

    or

    display = models.CharField(..., default=CHOICES[1][1])
    

提交回复
热议问题