mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added ability to attach file(s) to a part object
- Not yet fully working!
This commit is contained in:
parent
226828791f
commit
0550dad2d4
@ -2,6 +2,7 @@ from django.contrib import admin
|
||||
|
||||
from .models import PartCategory, Part
|
||||
from .models import BomItem
|
||||
from .models import PartAttachment
|
||||
|
||||
class PartAdmin(admin.ModelAdmin):
|
||||
|
||||
@ -15,6 +16,9 @@ class PartCategoryAdmin(admin.ModelAdmin):
|
||||
class BomItemAdmin(admin.ModelAdmin):
|
||||
list_display=('part', 'sub_part', 'quantity')
|
||||
|
||||
class PartAttachmentAdmin(admin.ModelAdmin):
|
||||
list_display = ('part', 'attachment')
|
||||
|
||||
"""
|
||||
class ParameterTemplateAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'units', 'format')
|
||||
@ -27,6 +31,7 @@ class ParameterAdmin(admin.ModelAdmin):
|
||||
admin.site.register(Part, PartAdmin)
|
||||
admin.site.register(PartCategory, PartCategoryAdmin)
|
||||
admin.site.register(BomItem, BomItemAdmin)
|
||||
admin.site.register(PartAttachment, PartAttachmentAdmin)
|
||||
|
||||
#admin.site.register(PartParameter, ParameterAdmin)
|
||||
#admin.site.register(PartParameterTemplate, ParameterTemplateAdmin)
|
||||
|
@ -133,6 +133,29 @@ class Part(models.Model):
|
||||
return projects
|
||||
"""
|
||||
|
||||
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)
|
||||
|
||||
class PartAttachment(models.Model):
|
||||
""" A PartAttachment links a file to a part
|
||||
Parts can have multiple files such as datasheets, etc
|
||||
"""
|
||||
|
||||
|
||||
part = models.ForeignKey(Part, on_delete=models.CASCADE,
|
||||
related_name='attachments')
|
||||
|
||||
attachment = models.FileField(upload_to=attach_file, null=True, blank=True)
|
||||
|
||||
|
||||
|
||||
class BomItem(models.Model):
|
||||
""" A BomItem links a part to its component items.
|
||||
|
Loading…
Reference in New Issue
Block a user