diff --git a/InvenTree/part/admin.py b/InvenTree/part/admin.py index c7fa2a6b6c..610feb9744 100644 --- a/InvenTree/part/admin.py +++ b/InvenTree/part/admin.py @@ -2,6 +2,7 @@ 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 @@ -16,6 +17,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 +41,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) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index cc7810fb85..80a4a5da35 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -310,15 +310,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): @@ -331,6 +324,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 bd6859777e..c97423ed86 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -62,6 +62,13 @@ {% endif %} + +

Attachments

+