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
5 from django.utils.translation import gettext_lazy as _
7 from .wikidata import WikidataAdminMixin
10 class AuthorAdmin(WikidataAdminMixin, admin.ModelAdmin):
22 list_filter = ["year_of_death", "priority", "collections", "status", "gender", "nationality"]
23 search_fields = ["first_name", "last_name", "wikidata"]
24 prepopulated_fields = {"slug": ("first_name", "last_name")}
25 autocomplete_fields = ["collections"]
28 admin.site.register(models.Author, AuthorAdmin)
31 class BookAdmin(WikidataAdminMixin, admin.ModelAdmin):
41 search_fields = ["title", "wikidata"]
42 autocomplete_fields = ["authors", "translators", "based_on", "collections", "epochs", "genres", "kinds"]
43 prepopulated_fields = {"slug": ("title",)}
44 list_filter = ["language", "pd_year", "collections"]
45 readonly_fields = ["wikidata_link"]
47 (None, {"fields": [("wikidata", "wikidata_link")]}),
86 def get_queryset(self, request):
87 qs = super().get_queryset(request)
88 if request.resolver_match.view_name.endswith("changelist"):
89 qs = qs.prefetch_related("authors", "translators")
93 admin.site.register(models.Book, BookAdmin)
96 class AuthorInline(admin.TabularInline):
97 model = models.Author.collections.through
98 autocomplete_fields = ["author"]
101 class BookInline(admin.TabularInline):
102 model = models.Book.collections.through
103 autocomplete_fields = ["book"]
106 class CollectionAdmin(admin.ModelAdmin):
107 list_display = ["name"]
108 autocomplete_fields = []
109 prepopulated_fields = {"slug": ("name",)}
110 search_fields = ["name"]
111 inlines = [AuthorInline, BookInline]
114 admin.site.register(models.Collection, CollectionAdmin)
117 class CategoryAdmin(admin.ModelAdmin):
118 search_fields = ["name"]
120 admin.site.register(models.Epoch, CategoryAdmin)
121 admin.site.register(models.Genre, CategoryAdmin)
122 admin.site.register(models.Kind, CategoryAdmin)