diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py
a
|
b
|
|
149 | 149 | validate_inline(inline, cls, model) |
150 | 150 | |
151 | 151 | def validate_inline(cls, parent, parent_model): |
152 | | |
| 152 | |
153 | 153 | # model is already verified to exist and be a Model |
154 | 154 | if cls.fk_name: # default value is None |
155 | 155 | f = get_field(cls, cls.model, cls.model._meta, 'fk_name', cls.fk_name) |
… |
… |
|
200 | 200 | raise ImproperlyConfigured('Both fieldsets and fields are specified in %s.' % cls.__name__) |
201 | 201 | if len(cls.fields) > len(set(cls.fields)): |
202 | 202 | raise ImproperlyConfigured('There are duplicate field(s) in %s.fields' % cls.__name__) |
| 203 | for field in cls.fields: |
| 204 | f = get_field(cls, model, opts, 'fields', field) |
| 205 | if isinstance(f, models.ManyToManyField) and f.rel.through and not f.rel.through._meta.auto_created: |
| 206 | raise ImproperlyConfigured("'fields' option can't include a ManyToManyField field that uses the 'through' option. Problem is in %s.fields, '%s' field." % (cls.__name__, field)) |
203 | 207 | |
204 | 208 | # fieldsets |
205 | 209 | if cls.fieldsets: # default value is None |
diff --git a/tests/regressiontests/admin_validation/models.py b/tests/regressiontests/admin_validation/models.py
a
|
b
|
|
26 | 26 | e = models.CharField(max_length=1) |
27 | 27 | |
28 | 28 | |
| 29 | class Author(models.Model): |
| 30 | name = models.CharField(max_length=30) |
| 31 | |
| 32 | |
| 33 | class Book(models.Model): |
| 34 | name = models.CharField(max_length=20) |
| 35 | authors = models.ManyToManyField(Author, through='AuthorsBooks') |
| 36 | |
| 37 | |
| 38 | class AuthorsBooks(models.Model): |
| 39 | author = models.ForeignKey(Author) |
| 40 | book = models.ForeignKey(Book) |
| 41 | |
29 | 42 | |
30 | 43 | __test__ = {'API_TESTS':""" |
31 | 44 | |
… |
… |
|
95 | 108 | |
96 | 109 | >>> validate_inline(TwoAlbumFKAndAnEInline, None, Album) |
97 | 110 | |
| 111 | # Regression test for #12203 - Fail more gracefully when a M2M field that |
| 112 | # specifies the 'through' option is included in the 'fields' ModelAdmin option. |
| 113 | |
| 114 | >>> class BookAdmin(admin.ModelAdmin): |
| 115 | ... fields = ['authors'] |
| 116 | |
| 117 | >>> validate(BookAdmin, Book) |
| 118 | Traceback (most recent call last): |
| 119 | ... |
| 120 | ImproperlyConfigured: 'fields' option can't include a ManyToManyField field that uses the 'through' option. Problem is in BookAdmin.fields, 'authors' field. |
| 121 | |
98 | 122 | """} |