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 _
6 from fnpdjango.actions import export_as_csv_action
8 from .wikidata import WikidataAdminMixin
11 class AuthorAdmin(WikidataAdminMixin, admin.ModelAdmin):
23 list_filter = ["year_of_death", "priority", "collections", "status", "gender", "nationality"]
24 search_fields = ["first_name", "last_name", "wikidata"]
25 prepopulated_fields = {"slug": ("first_name", "last_name")}
26 autocomplete_fields = ["collections"]
29 admin.site.register(models.Author, AuthorAdmin)
32 class BookAdmin(WikidataAdminMixin, admin.ModelAdmin):
42 search_fields = ["title", "wikidata"]
43 autocomplete_fields = ["authors", "translators", "based_on", "collections", "epochs", "genres", "kinds"]
44 prepopulated_fields = {"slug": ("title",)}
45 list_filter = ["language", "pd_year", "collections"]
46 readonly_fields = ["wikidata_link"]
47 actions = [export_as_csv_action()]
49 (None, {"fields": [("wikidata", "wikidata_link")]}),
88 def get_queryset(self, request):
89 qs = super().get_queryset(request)
90 if request.resolver_match.view_name.endswith("changelist"):
91 qs = qs.prefetch_related("authors", "translators")
95 admin.site.register(models.Book, BookAdmin)
98 class AuthorInline(admin.TabularInline):
99 model = models.Author.collections.through
100 autocomplete_fields = ["author"]
103 class BookInline(admin.TabularInline):
104 model = models.Book.collections.through
105 autocomplete_fields = ["book"]
108 class CollectionAdmin(admin.ModelAdmin):
109 list_display = ["name"]
110 autocomplete_fields = []
111 prepopulated_fields = {"slug": ("name",)}
112 search_fields = ["name"]
113 inlines = [AuthorInline, BookInline]
116 admin.site.register(models.Collection, CollectionAdmin)
119 class CategoryAdmin(admin.ModelAdmin):
120 search_fields = ["name"]
122 admin.site.register(models.Epoch, CategoryAdmin)
123 admin.site.register(models.Genre, CategoryAdmin)
124 admin.site.register(models.Kind, CategoryAdmin)