From c5c4bfa12aa0e8d4e8b46d77b6159f59330c3313 Mon Sep 17 00:00:00 2001 From: Emmanuelle Delescolle Date: Sun, 5 Oct 2014 20:06:51 +0200 Subject: [1.6.x] Fixed #23604 -- Allowed related m2m fields to be references in the admin. Thanks Simon Charette for review. Backport of a24cf21722 from master --- django/contrib/admin/options.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'django') 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() -- cgit v1.3