summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2020-01-07 11:52:09 +0100
committerCarlton Gibson <carlton.gibson@noumenal.es>2020-01-15 15:36:28 +0100
commit57468eaff3de78918be5fb15a7984e49d7d3d103 (patch)
treeee54fe217fa01c831a7cadb90ae12780db59311c /django/db
parent8712027b226f1400ea31f9c0500fbfe359dd9d07 (diff)
[3.0.x] Fixed #31124 -- Fixed setting of get_FOO_display() when overriding inherited choices.
Regression in 2d38eb0ab9f78d68c083a5b78b1eca39027b279a Backport of 29c126bb349526b5f1cd78facbe9f25906f18563 from master
Diffstat (limited to 'django/db')
-rw-r--r--django/db/models/fields/__init__.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index e8a65c541d..dcbb82e227 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -767,7 +767,11 @@ class Field(RegisterLookupMixin):
if not getattr(cls, self.attname, None):
setattr(cls, self.attname, self.descriptor_class(self))
if self.choices is not None:
- if not hasattr(cls, 'get_%s_display' % self.name):
+ # Don't override a get_FOO_display() method defined explicitly on
+ # this class, but don't check methods derived from inheritance, to
+ # allow overriding inherited choices. For more complex inheritance
+ # structures users should override contribute_to_class().
+ if 'get_%s_display' % self.name not in cls.__dict__:
setattr(
cls,
'get_%s_display' % self.name,