mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
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:
commit
90d2265dae
@ -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 """
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
<hr>
|
||||
|
||||
{% include "attachment_table.html" with attachments=part.attachments.all %}
|
||||
{% include "attachment_table.html" with attachments=part.part_attachments %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user