2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

Provide download link for part attachments

- Better upload management for attachment files (separated based on part ID)
This commit is contained in:
Oliver Walters 2019-04-18 00:14:53 +10:00
parent d9d4e0043a
commit e707eb3a2b
2 changed files with 7 additions and 10 deletions

View File

@ -372,15 +372,8 @@ class Part(models.Model):
def attach_file(instance, filename): def attach_file(instance, filename):
# Construct a path to store a file attachment
base = 'part_files' return os.path.join('part_files', str(instance.part.id), filename)
# TODO - For a new PartAttachment object, PK is NULL!!
# Prefix the attachment ID to the filename
fn = "{id}_{fn}".format(id=instance.pk, fn=filename)
return os.path.join(base, fn)
class PartAttachment(models.Model): class PartAttachment(models.Model):
@ -393,6 +386,10 @@ class PartAttachment(models.Model):
attachment = models.FileField(upload_to=attach_file, null=True, blank=True) attachment = models.FileField(upload_to=attach_file, null=True, blank=True)
@property
def basename(self):
return os.path.basename(self.attachment.name)
class BomItem(models.Model): class BomItem(models.Model):
""" A BomItem links a part to its component items. """ A BomItem links a part to its component items.

View File

@ -66,7 +66,7 @@
<h4>Attachments</h4> <h4>Attachments</h4>
<ul> <ul>
{% for attachment in part.attachments.all %} {% for attachment in part.attachments.all %}
<li><a href="{{ attachment.attachment }}">{{ attachment.attachment }}</a></li> <li><a href="/media/{{ attachment.attachment }}">{{ attachment.basename }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>