From cd8214ff4a7c530440432d1196af1e25ee276263 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 31 Aug 2020 22:26:46 +1000 Subject: [PATCH] Part: add function to get part attachments for *all* parents of a part --- InvenTree/part/models.py | 14 ++++++++++++++ InvenTree/part/templates/part/attachments.html | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index e5b035f856..c5da47b33e 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1087,6 +1087,20 @@ class Part(MPTTModel): return n + @property + def part_attachments(self): + """ + Return *all* attachments for this part, + potentially including attachments for template parts + above this one. + """ + + ancestors = self.get_ancestors(include_self=True) + + attachments = PartAttachment.objects.filter(part__in=ancestors) + + return attachments + def sales_orders(self): """ Return a list of sales orders which reference this part """ diff --git a/InvenTree/part/templates/part/attachments.html b/InvenTree/part/templates/part/attachments.html index 049ef0cd7a..aa31cd3f32 100644 --- a/InvenTree/part/templates/part/attachments.html +++ b/InvenTree/part/templates/part/attachments.html @@ -9,7 +9,7 @@
-{% include "attachment_table.html" with attachments=part.attachments.all %} +{% include "attachment_table.html" with attachments=part.part_attachments %} {% endblock %}