django中获取包含choice参数的字段值
class UserInfo(model.Model):
name = models.CharField()
addr_choice = (
(1, "北京"),
(2, "上海"),
)
addr = models.CharField(choice=addr_choice)
obj = UserInfo.objects.create(name="tom", addr=1)
print(obj.get_addr_display())
结果为:"北京"