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