How to limit the maximum value of a numeric field in a Django model?

后端 未结 6 1585
醉话见心
醉话见心 2020-11-27 09:56

Django has various numeric fields available for use in models, e.g. DecimalField and PositiveIntegerField. Although the former can be restricted to the number of decimal pla

6条回答
  •  星月不相逢
    2020-11-27 10:35

    I had this very same problem; here was my solution:

    SCORE_CHOICES = zip( range(1,n), range(1,n) )
    score = models.IntegerField(choices=SCORE_CHOICES, blank=True)
    

提交回复
热议问题