Merge pull request #945 from SchrodingersGat/template-attachments

Part: add function to get part attachments for *all* parents of a part
This commit is contained in:
Oliver 2020-08-31 22:38:02 +10:00 committed by GitHub
commit 90d2265dae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -1080,12 +1080,21 @@ class Part(MPTTModel):
""" """
n = self.attachments.count() return self.part_attachments.count()
if self.variant_of: @property
n += self.variant_of.attachments.count() 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): def sales_orders(self):
""" Return a list of sales orders which reference this part """ """ Return a list of sales orders which reference this part """

View File

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