Part: add function to get part attachments for *all* parents of a part

This commit is contained in:
Oliver Walters 2020-08-31 22:26:46 +10:00
parent 35cd3923a5
commit cd8214ff4a
2 changed files with 15 additions and 1 deletions

View File

@ -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 """

View File

@ -9,7 +9,7 @@
<hr>
{% include "attachment_table.html" with attachments=part.attachments.all %}
{% include "attachment_table.html" with attachments=part.part_attachments %}
{% endblock %}