[Django] #33964: get_FOO_display() doesn't work with field named that include underscore

10 views
Skip to first unread message

Django

unread,
Aug 29, 2022, 8:43:15 AM8/29/22
to django-...@googlegroups.com
#33964: get_FOO_display() doesn't work with field named that include underscore
-------------------------------------+-------------------------------------
Reporter: 80nph1r3 | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 4.1
layer (models, ORM) | Keywords: get_FOO_display()
Severity: Normal | model
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
If you try to use a get_FOO_display method on a field that contains
underscore, it apparently breaks the syntax and the method doesn't work

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

Django

unread,
Aug 29, 2022, 9:11:25 AM8/29/22
to django-...@googlegroups.com
#33964: get_FOO_display() doesn't work with field named that include underscore
-------------------------------------+-------------------------------------
Reporter: 80nph1r3 | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 4.1
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: get_FOO_display() | Triage Stage:
model | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => worksforme


Comment:

The following test passes for me. Please provide details to reproduce.
{{{#!diff
diff --git a/tests/model_regress/models.py b/tests/model_regress/models.py
index 350850393a..369eada93f 100644
--- a/tests/model_regress/models.py
+++ b/tests/model_regress/models.py
@@ -11,6 +11,7 @@ class Article(models.Model):
status = models.IntegerField(blank=True, null=True, choices=CHOICES)
misc_data = models.CharField(max_length=100, blank=True)
article_text = models.TextField()
+ the_status = models.IntegerField(blank=True, null=True,
choices=CHOICES)

class Meta:
ordering = ("pub_date", "headline")
diff --git a/tests/model_regress/tests.py b/tests/model_regress/tests.py
index 10dfbabcd9..cd7c6f3c48 100644
--- a/tests/model_regress/tests.py
+++ b/tests/model_regress/tests.py
@@ -56,8 +56,9 @@ class ModelTests(TestCase):
# NOTE: Part of the regression test here is merely parsing the
model
# declaration. The verbose_name, in particular, did not always
work.
a = Article.objects.create(
- headline="Look at me!", pub_date=datetime.datetime.now()
+ headline="Look at me!", pub_date=datetime.datetime.now(),
the_status=1,
)
+ self.assertIs(a.get_the_status_display(), 'first')
# An empty choice field should return None for the display name.
self.assertIs(a.get_status_display(), None)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33964#comment:1>

Reply all
Reply to author
Forward
0 new messages