summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorEmmanuelle Delescolle <emma@lasolution.be>2014-10-05 20:06:51 +0200
committerTim Graham <timograham@gmail.com>2014-10-06 08:35:16 -0400
commita24cf217220dca44b7bd5b36ad9c14a96bca486e (patch)
treedf014891557d404dee3a9fe979eaf7e62aff775e /django
parente501d4c505ede0c87c2d1a8667167314021489e2 (diff)
Fixed #23604 -- Allowed related m2m fields to be references in the admin.
Thanks Simon Charette for review.
Diffstat (limited to 'django')
-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 6edae7a5c5..bf8f2717c2 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -451,6 +451,11 @@ 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:
+ 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()