From 976319247c9e3d0a40d02966d91b4409ff32b7bd Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 27 Jul 2024 02:18:09 -0400 Subject: [PATCH] use edition cover if mising work cover --- catalog/book/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/catalog/book/models.py b/catalog/book/models.py index 9708119d..a10a6bc7 100644 --- a/catalog/book/models.py +++ b/catalog/book/models.py @@ -368,6 +368,14 @@ def delete(self, using=None, keep_parents=False, soft=True, *args, **kwargs): self.editions.clear() return super().delete(using, keep_parents, soft, *args, **kwargs) + @property + def cover_image_url(self): + url = super().cover_image_url + if url: + return url + e = next(filter(lambda e: e.cover_image_url, self.editions.all()), None) + return e.cover_image_url if e else None + def update_linked_items_from_external_resource(self, resource): """add Edition from resource.metadata['required_resources'] if not yet""" links = resource.required_resources + resource.related_resources