From 94da7eb2739d91e80607681bc61672ef769ca90c Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 24 Jan 2023 13:52:39 +0100 Subject: [PATCH] fixes --- src/catalogue/admin.py | 1 + src/catalogue/models.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/catalogue/admin.py b/src/catalogue/admin.py index 68a362b5..7acfa401 100644 --- a/src/catalogue/admin.py +++ b/src/catalogue/admin.py @@ -273,6 +273,7 @@ class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin): "estimate_source", "document_book__project", + "audience", "first_publication_year", "monthly_views_page", diff --git a/src/catalogue/models.py b/src/catalogue/models.py index 151a13e4..6f4fa1e9 100644 --- a/src/catalogue/models.py +++ b/src/catalogue/models.py @@ -294,6 +294,12 @@ class Book(WikidataModel): if b.project is None: return '' return b.project.name + def audience(self): + try: + return self.document_books.first().wldocument().book_info.audience or '' + except: + return '' + def get_estimated_costs(self): return { work_type: work_type.calculate(self) @@ -314,6 +320,9 @@ class Book(WikidataModel): if pbr is not None and pbr.timestamp.date() > cutoff: months = (this_month - pbr.timestamp.date()).days / 365 * 12 + if not months: + return + stats = self.bookmonthlystats_set.filter(date__gte=cutoff).aggregate( views_page=models.Sum('views_page'), views_reader=models.Sum('views_reader') -- 2.20.1