Ticket #12203: 12203-m2m-w-through-modeladmin-fields-option1.3.diff

File 12203-m2m-w-through-modeladmin-fields-option1.3.diff, 1.6 KB (added by VINAY KUMAR SHARMA, 5 years ago)

do not report error if M2M field has through_fields defined

  • django/contrib/admin/checks.py

    commit bef6e3794e6e29806675e8c4aea3f3f371977ae3
    Author: VINAY Kr. SHARMA <sharma_salient@hotmail.com>
    Date:   Mon Jun 23 14:38:08 2014 +0530
    
        Fixed: #12203 ManyToManyField with explicit through model can't be used as an admin field
    
    diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
    index 3350625..4f51cfb 100644
    a b class BaseModelAdminChecks(object): 
    177177                return []
    178178            else:
    179179                if (isinstance(field, models.ManyToManyField) and
    180                         not field.rel.through._meta.auto_created):
     180                        not field.rel.through._meta.auto_created) and field.rel.through_fields is None:
     181                    """ If user has defined through fields then return with no error """
    181182                    return [
    182183                        checks.Error(
    183184                            ("The value of '%s' cannot include the ManyToManyField '%s', "
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index e01cdd0..c178a8a 100644
    a b class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)): 
    262262        """
    263263        # If it uses an intermediary model that isn't auto created, don't show
    264264        # a field in admin.
    265         if not db_field.rel.through._meta.auto_created:
     265        if not db_field.rel.through._meta.auto_created and db_field.rel.through_fields is None:
    266266            return None
    267267        db = kwargs.get('using')
    268268
Back to Top