I am trying to open the uploaded file in Model clean_fields(),
class Person(models.Model):
attach = models.FileField(upload_to='attach')
def clean_fields(self, exclude=True):
f = open(self.attach.path, 'rb')
The problem is, before the model save(), self.attach.path is actually wrong. the upload_to path is missing. And the file does not exist, yet.
The self.attach.path only exists and is correct after the model’s save()
How do I validate an uploaded file’s content in the clean_fields() process? I want to raise ValidationError, not error after the model is saved.
okay, since no way was able to answer this, I figuered it out myself.
Then everything is in place.