Hi all,
I have this model:
class Product(VASTObject_NameUserGroupUnique):
image = models.ImageField(upload_to='product_images/', default=None, null=True, blank=True)
image_resource_id = models.IntegerField(default=None, null=True, blank=True)
image_uriref = models.URLField(max_length=512, null=True, blank=True)
def save(self, *args, **kwargs):
logger.info(f"Product: save():", *args, **kwargs)
if self.image:
path = self.image.path
url = self.image.url
logger.info(f"Product: save(): Image url: {url} (exists: {os.path.exists(path)})")
logger.info(f"Product: save(): Image path: {path} (exists: {os.path.exists(path)})")
if not os.path.exists(path):
# Image not found at this path. Look into product_images...
head_tail = os.path.split(path)
path = os.path.join(head_tail[0], 'product_images', head_tail[1])
logger.info(f"Product: save(): Trying new Image path: {path} (exists: {os.path.exists(path)})")
if os.path.exists(path):
head_tail = os.path.split(url)
url = os.path.join(head_tail[0], 'product_images', head_tail[1])
logger.info(f"Product: save(): Trying new Image url: {url} (exists: {os.path.exists(path)})")
super().save(*args, **kwargs)
When I create a new product, it seems to work. But when changing the image on an existing object, I get this output:
Product: save():
Product: save(): Image url: /media/20230520_174836.jpg (exists: False)
Product: save(): Image path: /backend/media/20230520_174836.jpg (exists: False)
Product: save(): Trying new Image path: /backend/media/product_images/20230520_174836.jpg (exists: False)
The fields in image seem correct, but the actual file is not in the media folder.
Where is my image file?
(I need o upload it into a digital assets management system).