Set Django IntegerField by choices=… name

后端 未结 10 884
南笙
南笙 2020-12-07 09:40

When you have a model field with a choices option you tend to have some magic values associated with human readable names. Is there in Django a convenient way to set these f

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 10:14

    Simply replace your numbers with the human readable values you would like. As such:

    PRIORITIES = (
    ('LOW', 'Low'),
    ('NORMAL', 'Normal'),
    ('HIGH', 'High'),
    )
    

    This makes it human readable, however, you'd have to define your own ordering.

提交回复
热议问题