2👍
✅
You need to override your Model’s save
method, not your Form’s.
class MyModel(models.Model):
# other fields
my_file = models.FileField(upload_to='uploaddir')
def save(self, *args, **kwargs):
new_name = 'file_name-random-chars.ext'
self.my_file.name = new_name
super(MyModel, self).save(*args, **kwargs)
Your ModelForm for MyModel
will call it’s model’s save method and do the trick.
Hope it helps 🙂
Source:stackexchange.com