mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
commit
6b05078fd2
@ -2,6 +2,7 @@ from django.contrib import admin
|
|||||||
from import_export.admin import ImportExportModelAdmin
|
from import_export.admin import ImportExportModelAdmin
|
||||||
|
|
||||||
from .models import PartCategory, Part
|
from .models import PartCategory, Part
|
||||||
|
from .models import PartAttachment
|
||||||
from .models import SupplierPart
|
from .models import SupplierPart
|
||||||
from .models import BomItem
|
from .models import BomItem
|
||||||
|
|
||||||
@ -16,6 +17,11 @@ class PartCategoryAdmin(admin.ModelAdmin):
|
|||||||
list_display = ('name', 'pathstring', 'description')
|
list_display = ('name', 'pathstring', 'description')
|
||||||
|
|
||||||
|
|
||||||
|
class PartAttachmentAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
|
list_display = ('part', 'attachment')
|
||||||
|
|
||||||
|
|
||||||
class BomItemAdmin(ImportExportModelAdmin):
|
class BomItemAdmin(ImportExportModelAdmin):
|
||||||
list_display = ('part', 'sub_part', 'quantity')
|
list_display = ('part', 'sub_part', 'quantity')
|
||||||
|
|
||||||
@ -35,5 +41,6 @@ class ParameterAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
admin.site.register(Part, PartAdmin)
|
admin.site.register(Part, PartAdmin)
|
||||||
admin.site.register(PartCategory, PartCategoryAdmin)
|
admin.site.register(PartCategory, PartCategoryAdmin)
|
||||||
|
admin.site.register(PartAttachment, PartAttachmentAdmin)
|
||||||
admin.site.register(BomItem, BomItemAdmin)
|
admin.site.register(BomItem, BomItemAdmin)
|
||||||
admin.site.register(SupplierPart, SupplierPartAdmin)
|
admin.site.register(SupplierPart, SupplierPartAdmin)
|
||||||
|
@ -310,15 +310,8 @@ class Part(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
def attach_file(instance, filename):
|
def attach_file(instance, filename):
|
||||||
|
# Construct a path to store a file attachment
|
||||||
base = 'part_files'
|
return os.path.join('part_files', str(instance.part.id), filename)
|
||||||
|
|
||||||
# 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):
|
class PartAttachment(models.Model):
|
||||||
@ -331,6 +324,10 @@ class PartAttachment(models.Model):
|
|||||||
|
|
||||||
attachment = models.FileField(upload_to=attach_file, null=True, blank=True)
|
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):
|
class BomItem(models.Model):
|
||||||
""" A BomItem links a part to its component items.
|
""" A BomItem links a part to its component items.
|
||||||
|
@ -62,6 +62,13 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<h4>Attachments</h4>
|
||||||
|
<ul>
|
||||||
|
{% for attachment in part.attachments.all %}
|
||||||
|
<li><a href="/media/{{ attachment.attachment }}">{{ attachment.basename }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user