How to rename an image with FileField type. Please tell me how to do it in *views* while uploading an image to S3.
import osfrom uuid import uuid4 def path_and_rename(path): def wrapper(instance, filename): ext = filename.split('.')[-1] # get filename if instance.pk: filename = '{}.{}'.format(instance.pk, ext) else: # set filename as random string filename = '{}.{}'.format(uuid4().hex, ext) # return the whole path to the file return os.path.join(path, filename) return wrapper FileField(upload_to=path_and_rename('upload/here/'), ...) *The above code works well in models.py file but throws back error during migration process. Please help me how can i solve this issue in views.py file because once i place the above code in models.py it works very well but if there is any change in model and i do a migration then it throws back an error.* -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1360d55d-24bb-4464-baac-ac012de048f8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.