Opened 15 years ago

Closed 15 years ago

#12209 closed (fixed)

ManyToManyField.through does not work as the model property of an inline when specified using a string

Reported by: David Gouldin Owned by: nobody
Component: contrib.admin Version: 1.1
Severity: Keywords:
Cc: dgouldin@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Using the following models:

class Author(models.Model):
    name = models.CharField(max_length=100)

class Book(models.Model):
    name = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author, through='AuthorsBooks')

class AuthorsBooks(models.Model):
    author = models.ForeignKey(Author)
    book = models.ForeignKey(Book)

... with this admin:

class AuthorsInline(admin.TabularInline):
    model = models.Book.authors.through

class BookAdmin(admin.ModelAdmin):
    inlines = [AuthorsInline]
    exclude = ('authors',)

admin.site.register(models.Book, BookAdmin)

... does not function. If you change the models to:

class AuthorsBooks(models.Model):
    author = models.ForeignKey('Author')
    book = models.ForeignKey('Book')

class Author(models.Model):
    name = models.CharField(max_length=100)

class Book(models.Model):
    name = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author, through=AuthorsBooks)

... the admin works just fine. This seems to be an issue with specifying Book.authors.through as a string instead of using the model class itself.

Change History (2)

comment:1 by David Gouldin, 15 years ago

Cc: dgouldin@… added

comment:2 by Russell Keith-Magee, 15 years ago

Resolution: fixed
Status: newclosed

(In [11736]) Fixed #12209 -- Made the through attribute on a m2m relation into a property to ensure that the fully resolved through model is always provdided. Thanks to dgouldin for the report.

Note: See TracTickets for help on using tickets.
Back to Top