What you want to do is handle the filename modification at model level, so that any uploads from your custom views, django admin and even django-rest-framework will be handled the same.
From your snippets, it looks like you’re trying to do this, but I don’t where
rename_and_path is defined.
So define the following method above your Shop model
def logo_dir_path(instance, filename): extension = filename.split('.')[-1] og_filename = filename.split('.') new_filename = "shop_%s.%s" % (instance.name, extension) return new_filename
Then on your logo field on the model, add the following attribute:
logo = models.ImageField(upload_to=logo_dir_path)
CLICK HERE to find out more related problems solutions.