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", "estimated_costs"]
47 actions = [export_as_csv_action()]
49 (None, {"fields": [("wikidata", "wikidata_link")]}),
83 ("estimated_chars", "estimated_verses", "estimate_source"),
90 def get_queryset(self, request):
91 qs = super().get_queryset(request)
92 if request.resolver_match.view_name.endswith("changelist"):
93 qs = qs.prefetch_related("authors", "translators")
97 admin.site.register(models.Book, BookAdmin)
100 class AuthorInline(admin.TabularInline):
101 model = models.Author.collections.through
102 autocomplete_fields = ["author"]
105 class BookInline(admin.TabularInline):
106 model = models.Book.collections.through
107 autocomplete_fields = ["book"]
110 class CollectionAdmin(admin.ModelAdmin):
111 list_display = ["name"]
112 autocomplete_fields = []
113 prepopulated_fields = {"slug": ("name",)}
114 search_fields = ["name"]
115 inlines = [AuthorInline, BookInline]
118 admin.site.register(models.Collection, CollectionAdmin)
121 class CategoryAdmin(admin.ModelAdmin):
122 search_fields = ["name"]
124 admin.site.register(models.Epoch, CategoryAdmin)
125 admin.site.register(models.Genre, CategoryAdmin)
126 admin.site.register(models.Kind, CategoryAdmin)
130 class WorkRateInline(admin.TabularInline):
131 model = models.WorkRate
132 autocomplete_fields = ['kinds', 'genres', 'epochs', 'collections']
135 class WorkTypeAdmin(admin.ModelAdmin):
136 inlines = [WorkRateInline]
138 admin.site.register(models.WorkType, WorkTypeAdmin)