Opened 4 years ago
Closed 4 years ago
#33186 closed New feature (invalid)
Clarify get_FOO_display returns name, not label, from models.Choices
| Reported by: | Andrew Chen Wang | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | docs, choices |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I think it would be nice if the docs explicitly mentioned that get_FOO_display returns name, not the label if you were to use models.IntegerChoices or models.TextChoices.
Change History (1)
comment:1 by , 4 years ago
| Easy pickings: | unset |
|---|---|
| Resolution: | → invalid |
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
As far as I'm aware
get_FOO_display()returns labels as expected:class YearInSchool(models.TextChoices): FRESHMAN = 'FR', 'Freshman' SOPHOMORE = 'SO', 'Sophomore' JUNIOR = 'JR', 'Junior' SENIOR = 'SR', 'Senior' GRADUATE = 'GR', 'Graduate' class MyModel(models.Model): foo = models.CharField(max_length=254, choices=YearInSchool.choices) >>> MyModel(foo='FR').get_foo_display()) Freshman