I have the following model:
class Image(models.Model): image = models.ImageField(upload_to=
file_upload_to)
I have a dynamic file_upload function:
def file_upload_to(instance, filename):
base = '_'.join([str(instance.item.pk), instance.item.slug])
return os.path.join('accounts', base, 'item', base_2, 'images', filename)
and in a ModelForm:
class ImageModelForm(ModelForm)
def save(self, commit=True):
image_obj = super().save(commit=commit)
product_image__task.delay(image_obj.image.path, image_obj.image.name,
image_obj.product_id) return image_obj
I tried also to wait for transaction:
transaction.on_commit( lambda:
product_image_crop_task.delay(image_obj.image.path, image_obj.image.name,
image_obj.product_id))
The file is saved properly in a path like:
media/account/12_blue/images/image_name.jpeg
The problem is that image_obj.image.path is not reporting the correct path,
but this path:
media/image_name.jpeg
I use the image path, further passing it as an argument to a task, but
because I received the wrong path, it will fail.
How can I fix this, and receive the correct path ? I tried also using
time.sleep(), nothing works, the path/location returned is wrong, even if
is saved to the correct one.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/7d57595e-95b5-49f4-a29a-34f73e30620d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.