-class BookAdmin(admin.ModelAdmin):
- list_display = ['title', 'public', '_published', '_new_publishable', 'project']
- list_filter = ['public', '_published', '_new_publishable', 'project']
- prepopulated_fields = {'slug': ['title']}
- search_fields = ['title']
+class AuthorAdmin(WikidataAdminMixin, admin.ModelAdmin):
+ list_display = [
+ "first_name",
+ "last_name",
+ "status",
+ "year_of_death",
+ "gender",
+ "nationality",
+ "priority",
+ "wikidata_link",
+ "slug",
+ ]
+ list_filter = ["year_of_death", "priority", "collections", "status", "gender", "nationality"]
+ search_fields = ["first_name", "last_name", "wikidata"]
+ prepopulated_fields = {"slug": ("first_name", "last_name")}
+ autocomplete_fields = ["collections"]
+
+
+admin.site.register(models.Author, AuthorAdmin)
+
+
+class BookAdmin(WikidataAdminMixin, admin.ModelAdmin):
+ list_display = [
+ "title",
+ "authors_str",
+ "translators_str",
+ "language",
+ "pd_year",
+ "priority",
+ "wikidata_link",
+ ]
+ search_fields = ["title", "wikidata"]
+ autocomplete_fields = ["authors", "translators", "based_on", "collections", "epochs", "genres", "kinds"]
+ prepopulated_fields = {"slug": ("title",)}
+ list_filter = ["language", "pd_year", "collections"]
+ readonly_fields = ["wikidata_link"]
+ actions = [export_as_csv_action()]
+ fieldsets = [
+ (None, {"fields": [("wikidata", "wikidata_link")]}),
+ (
+ _("Identification"),
+ {
+ "fields": [
+ "title",
+ "slug",
+ "authors",
+ "translators",
+ "language",
+ "based_on",
+ "pd_year",
+ ]
+ },
+ ),
+ (
+ _("Features"),
+ {
+ "fields": [
+ "epochs",
+ "genres",
+ "kinds",
+ ]
+ },
+ ),
+ (
+ _("Plan"),
+ {
+ "fields": [
+ "scans_source",
+ "text_source",
+ "priority",
+ "collections",
+ "notes",
+ ]
+ },
+ ),
+ ]
+
+ def get_queryset(self, request):
+ qs = super().get_queryset(request)
+ if request.resolver_match.view_name.endswith("changelist"):
+ qs = qs.prefetch_related("authors", "translators")
+ return qs