summaryrefslogtreecommitdiff
path: root/django/contrib/admin/options.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2014-11-16 16:42:09 +0100
committerTim Graham <timograham@gmail.com>2014-11-25 13:32:24 -0500
commit2a20bccda984e6d516bba3eb7e8f307185754a3b (patch)
treef46a4d9554e8b1cb2ae45e83137c361a610a9bc1 /django/contrib/admin/options.py
parentf46ebc680b4868d61aec629ceded380ef313a687 (diff)
[1.7.x] 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. Backport of f9c4e14aeca7df79991bca8ac2d743953cbd095c from master
Diffstat (limited to 'django/contrib/admin/options.py')
-rw-r--r--django/contrib/admin/options.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index cef9021326..3d0faf0e33 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -450,9 +450,9 @@ class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)):
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
@@ -463,8 +463,7 @@ class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)):
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):