# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django.contrib import admin
+from django.utils.html import escape
+from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from admin_numeric_filter.admin import RangeNumericFilter, NumericFilterModelAdmin
from fnpdjango.actions import export_as_csv_action
class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin):
list_display = [
- "title",
+ "smart_title",
"authors_str",
"translators_str",
"language",
for work_type, cost in obj.get_estimated_costs().items()
)
+ def smart_title(self, obj):
+ if obj.title:
+ return obj.title
+ if obj.notes:
+ n = obj.notes
+ if len(n) > 100:
+ n = n[:100] + '…'
+ return mark_safe(
+ '<em><small>' + escape(n) + '</small></em>'
+ )
+ return '---'
+ smart_title.short_description = _('Title')
+ smart_title.admin_order_field = 'title'
+
admin.site.register(models.Book, BookAdmin)
def authors_str(self):
return ", ".join(str(author) for author in self.authors.all())
authors_str.admin_order_field = 'authors__last_name'
+ authors_str.short_description = _('Author')
def translators_str(self):
return ", ".join(str(author) for author in self.translators.all())
translators_str.admin_order_field = 'translators__last_name'
+ translators_str.short_description = _('Translator')
def get_estimated_costs(self):
return {