From: Radek Czajka Date: Mon, 4 Apr 2022 10:41:41 +0000 (+0200) Subject: Catalogue: nicer browsing of books with just notes. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/bc53500052b8793cb7ac46c1da7f05ace7e8c371 Catalogue: nicer browsing of books with just notes. --- diff --git a/src/catalogue/admin.py b/src/catalogue/admin.py index 3e80557d..d417f741 100644 --- a/src/catalogue/admin.py +++ b/src/catalogue/admin.py @@ -2,6 +2,8 @@ # 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 @@ -32,7 +34,7 @@ admin.site.register(models.Author, AuthorAdmin) class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin): list_display = [ - "title", + "smart_title", "authors_str", "translators_str", "language", @@ -120,6 +122,20 @@ class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin): 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( + '' + escape(n) + '' + ) + return '---' + smart_title.short_description = _('Title') + smart_title.admin_order_field = 'title' + admin.site.register(models.Book, BookAdmin) diff --git a/src/catalogue/models.py b/src/catalogue/models.py index 45250bcf..75726a47 100644 --- a/src/catalogue/models.py +++ b/src/catalogue/models.py @@ -164,10 +164,12 @@ class Book(WikidataMixin, models.Model): 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 {