summaryrefslogtreecommitdiff
path: root/django/contrib/admin/options.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/contrib/admin/options.py')
-rw-r--r--django/contrib/admin/options.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 0b7a6ae7d9..a0b816ccf0 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -339,6 +339,11 @@ 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:
+ return True
+
# Make sure at least one of the models registered for this site
# references this field through a FK or a M2M relationship.
registered_models = set()