+class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin):
+ list_display = [
+ "title",
+ "authors_str",
+ "translators_str",
+ "language",
+ "pd_year",
+ "priority",
+ "wikidata_link",
+ ]
+ search_fields = ["title", "wikidata", "authors__first_name", "authors__last_name", "translators__first_name", "translators__last_name"]
+ autocomplete_fields = ["authors", "translators", "based_on", "collections", "epochs", "genres", "kinds"]
+ prepopulated_fields = {"slug": ("title",)}
+ list_filter = [
+ "language",
+ "based_on__language",
+ ("pd_year", RangeNumericFilter),
+ "collections",
+ "collections__category",
+ "epochs", "kinds", "genres",
+ "priority",
+ "authors__gender", "authors__nationality",
+ "translators__gender", "translators__nationality",
+ "document_book__chunk__stage",
+ "document_book__chunk__user",
+ ]
+ readonly_fields = ["wikidata_link", "estimated_costs"]
+ 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",
+ ("estimated_chars", "estimated_verses", "estimate_source"),
+ "estimated_costs",
+ ]
+ },
+ ),
+ ]
+
+ 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
+
+ def estimated_costs(self, obj):
+ return "\n".join(
+ "{}: {} zł".format(
+ work_type.name,
+ cost or '—'
+ )
+ for work_type, cost in obj.get_estimated_costs().items()
+ )
+