Answer the question
In order to leave comments, you need to log in
Django how to rename already loaded ImageField images?
Changed the Model field with ImageField image upload field
image = models.ImageField(upload_to=motor_image_rename, default=None, blank=True, unique=True)
def motor_image_rename(instance, filename):
ext = filename.split('.')[-1]
name = slugify(instance.motor.brand.title),slugify(instance.motor.title)
filename = "%s.%s" % (name, ext)
return os.path.join('motor/{brand}/'.format(brand=instance.motor.brand.title), filename)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question