diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index e5b035f856..26dd04ac52 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1080,12 +1080,21 @@ class Part(MPTTModel): """ - n = self.attachments.count() + return self.part_attachments.count() - if self.variant_of: - n += self.variant_of.attachments.count() + @property + def part_attachments(self): + """ + Return *all* attachments for this part, + potentially including attachments for template parts + above this one. + """ - return n + 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 %}