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())

结果为:"北京"

posted @ 2019-05-24 15:58  酷酷的狐狸  阅读(2275)  评论(0编辑  收藏  举报