#33186: Clarify get_FOO_display returns name, not label, from models.Choices
-------------------------------------+-------------------------------------
Reporter: Andrew Chen Wang | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: docs,choices | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* status: new => closed
* resolution: => invalid
* easy: 1 => 0
Comment:
> 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.
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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33186#comment:1>
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/074.e7b8439abd2bbf928b63ad472bdf82b8%40djangoproject.com.