From e707eb3a2b698c719b4952d37bf861c519f1ccec Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 18 Apr 2019 00:14:53 +1000 Subject: [PATCH] Provide download link for part attachments - Better upload management for attachment files (separated based on part ID) --- InvenTree/part/models.py | 15 ++++++--------- InvenTree/part/templates/part/part_base.html | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 1d2f447083..8b7e22da76 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -372,15 +372,8 @@ class Part(models.Model): def attach_file(instance, filename): - - base = 'part_files' - - # 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) + # Construct a path to store a file attachment + return os.path.join('part_files', str(instance.part.id), filename) class PartAttachment(models.Model): @@ -393,6 +386,10 @@ class PartAttachment(models.Model): 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): """ A BomItem links a part to its component items. diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 3e39e42e18..c97423ed86 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -66,7 +66,7 @@

Attachments