1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.contrib import admin
6 from .wikidata import WikidataAdminMixin
9 class AuthorAdmin(WikidataAdminMixin, admin.ModelAdmin):
19 list_filter = ["year_of_death", "priority", "collections", "status"]
20 search_fields = ["first_name", "last_name", "wikidata"]
21 prepopulated_fields = {"slug": ("first_name", "last_name")}
22 autocomplete_fields = ["collections"]
25 admin.site.register(models.Author, AuthorAdmin)
28 class BookAdmin(WikidataAdminMixin, admin.ModelAdmin):
38 search_fields = ["title", "wikidata"]
39 autocomplete_fields = ["authors", "translators", "based_on", "collections"]
40 prepopulated_fields = {"slug": ("title",)}
41 list_filter = ["language", "pd_year", "collections"]
42 readonly_fields = ["wikidata_link"]
44 (None, {"fields": [("wikidata", "wikidata_link")]}),
73 def get_queryset(self, request):
74 qs = super().get_queryset(request)
75 if request.resolver_match.view_name.endswith("changelist"):
76 qs = qs.prefetch_related("authors", "translators")
80 admin.site.register(models.Book, BookAdmin)
83 class AuthorInline(admin.TabularInline):
84 model = models.Author.collections.through
85 autocomplete_fields = ["author"]
88 class BookInline(admin.TabularInline):
89 model = models.Book.collections.through
90 autocomplete_fields = ["book"]
93 class CollectionAdmin(admin.ModelAdmin):
94 list_display = ["name"]
95 autocomplete_fields = []
96 prepopulated_fields = {"slug": ("name",)}
97 search_fields = ["name"]
98 inlines = [AuthorInline, BookInline]
101 admin.site.register(models.Collection, CollectionAdmin)