nubela
nubela

Reputation: 17294

How do I change the directory of InMemoryUploadedFile?

It seems that if I do not create a ModelForm from a model, and create a new object and save it, it will not respect the field's upload directory.

How do I change the directory of a InMemoryUploadedFile so I can manually implement the upload dir? Because the InMemoryUploadedFile obj is just the filename, and I would like to add the upload dir parameters. Thank you!

def add_image(self, image):
    pi = ProductImages()
    pi.image = image
    pi.save()
    self.o_gallery_images.add(pi)
    return True

(Code that does not respect the upload dir of ProductImages "image" field)

Upvotes: 0

Views: 870

Answers (1)

Joshua Partogi
Joshua Partogi

Reputation: 16425

How did you define the attribute of image in your ProductImages model? Did you have upload_to argument in your FileField?

class ProductImages(models.Model):
    image = models.FileField(upload_to="images/")

Upvotes: 1

Related Questions