[Django] #33186: Clarify get_FOO_display returns name, not label, from models.Choices

56 views
Skip to first unread message

Django

unread,
Oct 10, 2021, 3:07:02 PM10/10/21
to django-...@googlegroups.com
#33186: Clarify get_FOO_display returns name, not label, from models.Choices
-------------------------------------+-------------------------------------
Reporter: Andrew | Owner: nobody
Chen Wang |
Type: New | Status: new
feature |
Component: Database | Version: dev
layer (models, ORM) |
Severity: Normal | Keywords: docs,choices
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/33186>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 11, 2021, 12:48:50 AM10/11/21
to django-...@googlegroups.com
#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>

Reply all
Reply to author
Forward
0 new messages