#31124 closed Bug (fixed)
Model.get_FOO_display() does not work correctly with inherited choices. — at Version 2
| Reported by: | Yash Jhunjhunwala | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 3.0 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Carlton Gibson, Sergey Fedoseev | 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 (last modified by )
Given a base model with choices A containing 3 tuples
Child Model inherits the base model overrides the choices A and adds 2 more tuples
get_foo_display does not work correctly for the new tuples added
Example:
class A(models.Model):
foo_choice = Choices(("A","output1"),("B","output2"))
field_foo = models.CharField(max_length=254,choices=foo_choice)
class Meta:
abstract:True
class B(A):
foo_choice = Choices(("A","output1"),("B","output2"),("C","output3"))
field_foo = models.CharField(max_length=254,choices=foo_choice)
Upon invoking get_field_foo_display() on instance of B ,
For value "A" and "B" the output works correctly i.e. returns "output1" / "output2"
but for value "C" the method returns "C" and not "output3" which is the expected behaviour
Change History (2)
follow-up: 2 comment:1 by , 6 years ago
| Component: | Uncategorized → Database layer (models, ORM) |
|---|---|
| Easy pickings: | unset |
| Resolution: | → needsinfo |
| Status: | new → closed |
| Summary: | get foo display - model inheritance does not work correctly → Model.get_FOO_display() does not work correctly with inherited choices. |
comment:2 by , 6 years ago
| Description: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.
Thanks for this report. Can you provide models and describe expected behavior? Can you also check if it's not a duplicate of #30931?, that was fixed in Django 2.2.7.