mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
Do not duplicate images when copying a part
- Simply reference the existing image
This commit is contained in:
parent
17c10da10e
commit
725eb3c538
@ -136,18 +136,9 @@ def rename_part_image(instance, filename):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
base = 'part_images'
|
base = 'part_images'
|
||||||
|
fname = os.path.basename(filename)
|
||||||
|
|
||||||
if filename.count('.') > 0:
|
return os.path.join(base, fname)
|
||||||
ext = filename.split('.')[-1]
|
|
||||||
else:
|
|
||||||
ext = ''
|
|
||||||
|
|
||||||
fn = 'part_{pk}_img'.format(pk=instance.pk)
|
|
||||||
|
|
||||||
if ext:
|
|
||||||
fn += '.' + ext
|
|
||||||
|
|
||||||
return os.path.join(base, fn)
|
|
||||||
|
|
||||||
|
|
||||||
def match_part_names(match, threshold=80, reverse=True, compare_length=False):
|
def match_part_names(match, threshold=80, reverse=True, compare_length=False):
|
||||||
@ -832,10 +823,8 @@ class Part(models.Model):
|
|||||||
# Copy the part image
|
# Copy the part image
|
||||||
if kwargs.get('image', True):
|
if kwargs.get('image', True):
|
||||||
if other.image:
|
if other.image:
|
||||||
image_file = ContentFile(other.image.read())
|
# Reference the other image from this Part
|
||||||
image_file.name = rename_part_image(self, other.image.url)
|
self.image = other.image
|
||||||
|
|
||||||
self.image = image_file
|
|
||||||
|
|
||||||
# Copy the BOM data
|
# Copy the BOM data
|
||||||
if kwargs.get('bom', False):
|
if kwargs.get('bom', False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user