summaryrefslogtreecommitdiff
path: root/django
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:26:50 -0500
commitf9c4e14aeca7df79991bca8ac2d743953cbd095c (patch)
treea3945c7f39cb64f43f61a503e5df88df0ef604e5 /django
parente0d1f2684ae60573b209783f9fd4f9db163ad704 (diff)
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.
Diffstat (limited to 'django')
-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 04a3552780..726c1b3d4d 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -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):