Changes between Initial Version and Version 2 of Ticket #31124


Ignore:
Timestamp:
Dec 27, 2019, 4:43:37 AM (5 years ago)
Author:
Yash Jhunjhunwala
Comment:

Replying to felixxm:

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.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #31124

    • Property Component UncategorizedDatabase layer (models, ORM)
    • Property Easy pickings unset
    • Property Resolutionneedsinfo
    • Property Status newclosed
    • Property Summary get foo display - model inheritance does not work correctlyModel.get_FOO_display() does not work correctly with inherited choices.
  • Ticket #31124 – Description

    initial v2  
    22Child Model inherits the base model overrides the choices A and adds 2 more tuples
    33get_foo_display does not work correctly for the new tuples added
     4
     5Example:
     6
     7
     8{{{
     9class A(models.Model):
     10   foo_choice = Choices(("A","output1"),("B","output2"))
     11   field_foo = models.CharField(max_length=254,choices=foo_choice)
     12   class Meta:
     13       abstract:True
     14
     15class B(A):
     16   foo_choice = Choices(("A","output1"),("B","output2"),("C","output3"))
     17   field_foo = models.CharField(max_length=254,choices=foo_choice)
     18}}}
     19
     20Upon invoking get_field_foo_display() on instance of B ,
     21For value "A" and "B" the output works correctly i.e. returns "output1" / "output2"
     22but for value "C" the method returns "C" and not "output3" which is the expected behaviour
     23
Back to Top