1 from django.contrib import admin
3 from .wikidata import WikidataAdminMixin
6 class AuthorAdmin(WikidataAdminMixin, admin.ModelAdmin):
16 list_filter = ["year_of_death", "priority", "collections", "status"]
17 search_fields = ["first_name", "last_name", "wikidata"]
18 prepopulated_fields = {"slug": ("first_name", "last_name")}
19 autocomplete_fields = ["collections"]
22 admin.site.register(models.Author, AuthorAdmin)
25 class BookAdmin(WikidataAdminMixin, admin.ModelAdmin):
35 search_fields = ["title", "wikidata"]
36 autocomplete_fields = ["authors", "translators", "based_on", "collections"]
37 prepopulated_fields = {"slug": ("title",)}
38 list_filter = ["language", "pd_year", "collections"]
39 readonly_fields = ["wikidata_link"]
41 (None, {"fields": [("wikidata", "wikidata_link")]}),
70 def get_queryset(self, request):
71 qs = super().get_queryset(request)
72 if request.resolver_match.view_name.endswith("changelist"):
73 qs = qs.prefetch_related("authors", "translators")
77 admin.site.register(models.Book, BookAdmin)
80 class AuthorInline(admin.TabularInline):
81 model = models.Author.collections.through
82 autocomplete_fields = ["author"]
85 class BookInline(admin.TabularInline):
86 model = models.Book.collections.through
87 autocomplete_fields = ["book"]
90 class CollectionAdmin(admin.ModelAdmin):
91 list_display = ["name"]
92 autocomplete_fields = []
93 prepopulated_fields = {"slug": ("name",)}
94 search_fields = ["name"]
95 inlines = [AuthorInline, BookInline]
98 admin.site.register(models.Collection, CollectionAdmin)