Commit f9c4e14a authored by Simon Charette's avatar Simon Charette Committed by Tim Graham
Browse files

Fixed #23754 -- Always allowed reference to the primary key in the admin

This change allows dynamically created inlines "Add related" button to work
correcly as long as their associated foreign key is pointing to the primary
key of the related model.

Thanks to amorce for the report, Julien Phalip for the initial patch,
and Collin Anderson for the review.
parent e0d1f268
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -454,9 +454,9 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)):
        except FieldDoesNotExist:
            return False

        # Check whether this model is the origin of a M2M relationship
        # in which case to_field has to be the pk on this model.
        if opts.many_to_many and field.primary_key:
        # Always allow referencing the primary key since it's already possible
        # to get this information from the change view URL.
        if field.primary_key:
            return True

        # Make sure at least one of the models registered for this site
@@ -467,8 +467,7 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)):
            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()):
        for related_object in opts.get_all_related_objects(include_hidden=True):
            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):
+8 −1
Original line number Diff line number Diff line
@@ -4,7 +4,14 @@ Django 1.4.17 release notes

*Under development*

Django 1.4.17 ...
Django 1.4.17 fixes a regression in the 1.4.14 security release.

Additionally, Django's vendored version of six, :mod:`django.utils.six`, has
been upgraded to the latest release (1.8.0).

Bugfixes
========

* Fixed a regression with dynamically generated inlines and allowed field
  references in the admin
  (`#23754 <http://code.djangoproject.com/ticket/23754>`_).
+14 −0
Original line number Diff line number Diff line
===========================
Django 1.5.12 release notes
===========================

*Under development*

Django 1.5.12 fixes a regression in the 1.5.9 security release.

Bugfixes
========

* Fixed a regression with dynamically generated inlines and allowed field
  references in the admin
  (`#23754 <http://code.djangoproject.com/ticket/23754>`_).
+7 −1
Original line number Diff line number Diff line
@@ -4,7 +4,13 @@ Django 1.6.9 release notes

*Under development*

Django 1.6.9 ...
Django 1.6.9 fixes a regression in the 1.6.6 security release.

Additionally, Django's vendored version of six, :mod:`django.utils.six`, has
been upgraded to the latest release (1.8.0).

Bugfixes
========

* Fixed a regression with dynamically generated inlines and allowed field
  references in the admin (:ticket:`23754`).
+3 −0
Original line number Diff line number Diff line
@@ -83,3 +83,6 @@ Bugfixes

* Added missing context to the admin's ``delete_selected`` view that prevented
  custom site header, etc. from appearing (:ticket:`23898`).

* Fixed a regression with dynamically generated inlines and allowed field
  references in the admin (:ticket:`23754`).
Loading