How to rename the uploaded image?

There is a model in which there is a field by which the images are saved.
The names of sborrati totally arbitrary.
Also in the model we specify the required name 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)

After save a model in the admin interface to automatically change the names we need?

As I understand it you need to use a post_save?

But what do you want to write? Seen a lot of code with renaming the save path, but the path that I was just happy with.

def rename_name_cover(.....):

post_save.connect(rename_name_cover, sender=Cover)
March 12th 20 at 08:03
2 answers
March 12th 20 at 08:05
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)

Something like that
We need to change the image name, not the path on which to save it. - Janet.Ra commented on March 12th 20 at 08:08
@Janet.Ra, filename override so we can function.
Don't forget to take the extension))
filename = 'new_file_name.' + filename.strip('.')[-1]
- Heidi_Hauck commented on March 12th 20 at 08:11
March 12th 20 at 08:07
We need to change the image name, not the path on which to save it.

Find more questions by tags Django