#31313: Error in Example in Model field reference > Field.choices > Enumeration
types
-----------------------------------------+------------------------
Reporter: lhopkins | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
The example in the new Field.choices Enumeration types documentation has
an error:
{{{
class Student(models.Model):
class YearInSchool(models.TextChoices):
FRESHMAN = 'FR', _('Freshman')
SOPHOMORE = 'SO', _('Sophomore')
JUNIOR = 'JR', _('Junior')
SENIOR = 'SR', _('Senior')
GRADUATE = 'GR', _('Graduate')
year_in_school = models.CharField(
max_length=2,
choices=YearInSchool.choices,
default=YearInSchool.FRESHMAN,
)
def is_upperclass(self):
return self.year_in_school in {YearInSchool.JUNIOR,
YearInSchool.SENIOR}
}}}
The method `is_upperclass()` attempts to access the `YearInSchool` class
directly, but cannot. The method should be:
{{{
def is_upperclass(self):
return self.year_in_school in {self.YearInSchool.JUNIOR,
self.YearInSchool.SENIOR}
}}}
or:
{{{
def is_upperclass(self):
return self.year_in_school in {Student.YearInSchool.JUNIOR,
Student.YearInSchool.SENIOR}
}}}
https://docs.djangoproject.com/en/3.0/ref/models/fields/#enumeration-types
--
Ticket URL: <https://code.djangoproject.com/ticket/31313>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.8e5943e058270a73ea334b53a3980bd6%40djangoproject.com.