I'm writing a model for a website. When a user adds an instance of the model through the Django admin, I want to catch the event and automatically generate files, including adding a reference path field for those created files.
The model form (used for the admin site) has a clean
method that can be overridden. I can create and update files and fields through this.
def clean(self):
info = self.cleaned_data.get('info')
... #Generate IO paths from info
self.cleaned_data['template_path'] = template_path
self.instance.template_path = template_path
return self.cleaned_data
I need to create a distinction between add
and change
events, so I'm not writing files and changing the pathing post object creation. Is there a way to do this within clean
, or should I be looking elsewhere to create fields & update fields?