mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-12 10:05:39 +00:00
Added ability to attach file(s) to a part object
- Not yet fully working!
This commit is contained in:
@ -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.
|
||||
|
Reference in New Issue
Block a user