I have a model with some customizations in the save method.
def SomeModel(models.Model):
def save(self, *args, **kwargs):
if not kwargs.pop('skip_expensive_processing', False):
do_expensice_processing()
return super(SomeModel, self).save(*args, **kwargs)
Basically, whenever the save method gets called, I want some expensive process to be executed
But when doing a bunch a saves together (a mass import), I don’t want to do the expensive processing on each save. I want to do the expensive process once after all the objects are saved.
In in case of a mass save, the objects are being created through a ModelForm. I need to find some way to modify the form so that when the form calls the save method on SomeModel, it pases on that skip_expensive_processing keyword arg. How do I do this?
I loked through te source of the ModelForm.save() method, but it doesn’t seem to be caling the model save method in a too straight forward manner…
You probably don’t need to override the modelform’s
savemethod. You should just be able to passcommit=True, and then the model save won’t be called at all.