让我们看一下这个例子:
class Author(models.Model):
...
class Book(models.Model):
author = models.ForeignKey(Author, related_name='books'...)
...
class Chapter(models.Model):
book = models.ForeignKey(Book, related_name='chapters' ...)
...
对于管理员,让我们ChapterAdmin像这样配置:
class ChapterAdmin(admin.ModelAdmin):
list_filter = ('book__author', 'book',)
...
这通过相关Author和提供了很好的过滤器Book。
问题来了:
当用户点击一个Authorinbook__author过滤器时,主表中的结果会被相应地过滤。好的。但是book过滤器仍然列出所有可用Books的,不管book_author过滤器。Is there a way to make the bookfilter dependent of book__authorfilter such that when an Authoris selected, only Booksby that are related to the Authorare listed in filter options?