summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2014-08-21 11:55:23 -0400
committerSimon Charette <charette.s@gmail.com>2014-08-27 22:12:37 -0400
commit4685026840f0e2b895f980b6a33ad1b282aa7852 (patch)
tree3f2e5900bfccaf23c7ef2ea7ddc3438cdca38a20 /django
parent8adc56ca78fa362dc59de81b641e6d65b6abf289 (diff)
[1.4.x] Fixed #23329 -- Allowed inherited and m2m fields to be referenced in the admin.
Thanks to Trac alias Markush2010 and ross for the detailed reports. Backport of 3cbb759 from master
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admin/options.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index cf3497b93c..fa7a6f0b9c 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -278,11 +278,13 @@ class BaseModelAdmin(object):
return False
# Make sure at least one of the models registered for this site
- # references this field.
+ # references this field through a FK or a M2M relationship.
registered_models = self.admin_site._registry
- for related_object in opts.get_all_related_objects():
- if (related_object.model in registered_models and
- field == related_object.field.rel.get_related_field()):
+ for related_object in (opts.get_all_related_objects() +
+ opts.get_all_related_many_to_many_objects()):
+ related_model = related_object.model
+ if (any(issubclass(model, related_model) for model in registered_models) and
+ related_object.field.rel.get_related_field() == field):
return True
return False