How do I rename image that I uploaded through Django Rest Framework #8808
-
I was try to rename image that I uploaded through Django API, Models.py serializers.py views.py |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Solution: To rename the filename that we are uploaded using drfdef image_dir_path(instance, filename): Create your models here.class ResumeModel(models.Model): |
Beta Was this translation helpful? Give feedback.
Solution:
To rename the filename that we are uploaded using drf
def image_dir_path(instance, filename):
extension = filename.split('.')[-1]
new_filename = "pimages/candidate_%s.%s" % (instance.name, extension)
return new_filename
Create your models here.
class ResumeModel(models.Model):
name = models.CharField(max_length=100)
email = models.EmailField()
dob = models.DateField(auto_now=False, auto_now_add=False)
state = models.CharField(choices=STATE_LIST, max_length=50)
gender = models.CharField(choices=GENDER_LIST, max_length=20)
location = models.CharField(max_length=100)
# pimage = models.ImageField(upload_to='pimages', blank=True)
pimage = models.ImageField(upload_to=image_dir_path, b…