diff options
| author | Simon Charette <charette.s@gmail.com> | 2014-09-04 17:04:53 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2014-09-08 13:49:07 -0400 |
| commit | 342ccbddc1f2362f867e030befaeb10449cf4539 (patch) | |
| tree | c1060a9cd713ff5e5b60c6b93eececcff2722a71 /django | |
| parent | cbbc7131c1cb0ed40280198a5dad8f5e8023f774 (diff) | |
Fixed #23431 -- Allowed inline and hidden references to admin fields.
This fixes a regression introduced by the 53ff096982 security fix.
Thanks to @a1tus for the report and Tim for the review.
refs #23329.
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/admin/options.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 7f6816a172..f7fce09ddc 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -439,6 +439,10 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)): return clean_lookup in valid_lookups def to_field_allowed(self, request, to_field): + """ + Returns True if the model associated with this admin should be + allowed to be referenced by the specified field. + """ opts = self.model._meta try: @@ -448,8 +452,13 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)): # Make sure at least one of the models registered for this site # 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() + + registered_models = set() + for model, admin in self.admin_site._registry.items(): + registered_models.add(model) + for inline in admin.inlines: + registered_models.add(inline.model) + + for related_object in (opts.get_all_related_objects(include_hidden=True) + 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 |
