Answer the question
In order to leave comments, you need to log in
How to rename uploaded image?
There is a model in which there is a field with which images are saved.
The names of the images are completely arbitrary.
Also in the model we specify the name we need name_cover
class Cover(models.Model):
name_cover = models.CharField(max_length=100, blank=True, null=True)
cover = models.ImageField(upload_to='uploads/', blank=True)
def rename_name_cover(.....):
post_save.connect(rename_name_cover, sender=Cover)
Answer the question
In order to leave comments, you need to log in
def content_file_name(instance, filename):
return '/'.join(['content', instance.user.username, filename])
class Content(models.Model):
name = models.CharField(max_length=200)
file = models.ImageField(upload_to=content_file_name)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question