标签:参数 fir strong erb model gen splay lint str
# models.py class UserInfo(models.Model): gender_choices = ( (1, "男"), (2, "女"), (3, "保密")) gender = models.SmallIntegerField(verbose_name="性别", choices=gender_choices)
我们在前端显示的是"男"、"女"、"保密",而不是1、2、3,则需要拿到这张表的对象(obj),使用 obj.get_字段名_display() 即可。
obj = models.UserInfo.objects.filter(pk=1).first() obj.get_gender_display()
models中,对于(Small)IntegerField类型字段的choices参数在前端的展示
标签:参数 fir strong erb model gen splay lint str
原文地址:https://www.cnblogs.com/believepd/p/10167296.html