#31313 closed Cleanup/optimization (fixed)
Error in Example in Model field reference > Field.choices > Enumeration types
Reported by: | Lee Hopkins | Owned by: | Andrey Doroschenko |
---|---|---|---|
Component: | Documentation | Version: | 3.0 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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
Change History (5)
comment:1 by , 5 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 5 years ago
Owner: | changed from | to
---|---|
Severity: | Normal → Release blocker |
Status: | new → assigned |
comment:3 by , 5 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
PR