From 00199c26de3c6f4064eda744ad0e6a865e884a99 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 17 Apr 2019 23:58:13 +1000 Subject: [PATCH 1/4] Add part attachments to the admin interface --- InvenTree/part/admin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/admin.py b/InvenTree/part/admin.py index c7fa2a6b6c..f37e656405 100644 --- a/InvenTree/part/admin.py +++ b/InvenTree/part/admin.py @@ -2,10 +2,10 @@ from django.contrib import admin from import_export.admin import ImportExportModelAdmin from .models import PartCategory, Part +from .models import PartAttachment from .models import SupplierPart from .models import BomItem - class PartAdmin(ImportExportModelAdmin): list_display = ('name', 'IPN', 'description', 'total_stock', 'category') @@ -16,6 +16,11 @@ class PartCategoryAdmin(admin.ModelAdmin): list_display = ('name', 'pathstring', 'description') +class PartAttachmentAdmin(admin.ModelAdmin): + + list_display = ('part', 'attachment') + + class BomItemAdmin(ImportExportModelAdmin): list_display = ('part', 'sub_part', 'quantity') @@ -35,5 +40,6 @@ class ParameterAdmin(admin.ModelAdmin): admin.site.register(Part, PartAdmin) admin.site.register(PartCategory, PartCategoryAdmin) +admin.site.register(PartAttachment, PartAttachmentAdmin) admin.site.register(BomItem, BomItemAdmin) admin.site.register(SupplierPart, SupplierPartAdmin) From d9d4e0043aad51a3b88928dc0a33ebaf51f6e233 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 18 Apr 2019 00:01:19 +1000 Subject: [PATCH 2/4] Display list of part attachments --- InvenTree/part/templates/part/part_base.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index bd6859777e..3e39e42e18 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -62,6 +62,13 @@ {% endif %} + +

Attachments

+ From e707eb3a2b698c719b4952d37bf861c519f1ccec Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 18 Apr 2019 00:14:53 +1000 Subject: [PATCH 3/4] 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

From 3bac4fc9ee6fe81c81fae4341c5dc49d66d3fa95 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 18 Apr 2019 00:20:49 +1000 Subject: [PATCH 4/4] Added some pepper --- InvenTree/part/admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/part/admin.py b/InvenTree/part/admin.py index f37e656405..610feb9744 100644 --- a/InvenTree/part/admin.py +++ b/InvenTree/part/admin.py @@ -6,6 +6,7 @@ from .models import PartAttachment from .models import SupplierPart from .models import BomItem + class PartAdmin(ImportExportModelAdmin): list_display = ('name', 'IPN', 'description', 'total_stock', 'category')