mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Provide download link for part attachments
- Better upload management for attachment files (separated based on part ID)
This commit is contained in:
parent
d9d4e0043a
commit
e707eb3a2b
@ -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.
|
||||
|
@ -66,7 +66,7 @@
|
||||
<h4>Attachments</h4>
|
||||
<ul>
|
||||
{% for attachment in part.attachments.all %}
|
||||
<li><a href="{{ attachment.attachment }}">{{ attachment.attachment }}</a></li>
|
||||
<li><a href="/media/{{ attachment.attachment }}">{{ attachment.basename }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user