Имею две модели, например, Book и Author:
class Author(models.Model): #... class Book(models.Model): #... author = models.ForeignKey(Author, on_delete=models.CASCADE, default=0, null=False)
AuthorAdmin(admin.ModelAdmin): list_display = ("books_list") def books_list(self, obj): url = urlresolvers.reverse("admin:author_book_changelist") return u'<a href="%s?%s=%d">%s</a>' % (url, "id", obj.id, "Books") books_list.short_description = "Book" books_list.allow_tags=True BookAdmin(admin.ModelAdmin): def get_model_perms(self, request): """Return empty perms dict thus hiding the model from admin index.""" return {} def get_queryset(self, request): qs = super(BookAdmin, self).get_queryset(request) author_id = request.GET.get('id') return qs.filter(author=author_id)
qs.filter(author=author_id)