[Django]-While saving a Django model instance, in what order are my clean() and save() overrides applied relative to methods used as ModelField attributes?

3👍

If there is a callable for the upload_to argument, it is called during the save() method of the model base. The save() is of course called after clean(), so you do NOT need to strip() any fields if you’ve already done so in the clean() method.

You can see where the code is called on line 90 of the Django source code: https://code.djangoproject.com/browser/django/trunk/django/db/models/fields/files.py

generate_filename is the stored variable that points to whatever you passed into upload_to.

So, the order is form submit -> model.full_clean() -> overridden clean() -> save(), which calls upload_to()

👤Jordan

Leave a comment