[note] get CHOICES

models.py

MY_CHOICES = (
    ("A", "a item"),
    ("B", "b item"),
    ("C", "c item"),
    ("D", "d item"),
)

class Test(models.Model):
    choice = models.CharField("Choice", max_length=20, choices=MY_CHOICES )


get choice value in views.py


object = Test.objects.get(choice="A")
choice = object.get_choice_display()


choice is "a item".

張貼留言

0 留言