Answers for "django models choices example"

3

field.choices django

Will create a select box for this in the model form. Use can select from the
options.The first element in each tuple is the actual value to be set on the model, 
and the second element is the human-readable name. For example:
YEAR_IN_SCHOOL_CHOICES = [
        (FRESHMAN, 'Freshman'),
        (SOPHOMORE, 'Sophomore'),
        (JUNIOR, 'Junior'),
        (SENIOR, 'Senior'),
        (GRADUATE, 'Graduate'),
    ]
    year_in_school = models.CharField(
        max_length=2,
        choices=YEAR_IN_SCHOOL_CHOICES,
        default=FRESHMAN,
    )
Posted by: Guest on May-04-2021

Python Answers by Framework

Browse Popular Code Answers by Language