[Fixed]-Django: ModelForm access instance of new object

1👍

It isn’t necessary to override the ModelForm save() function. Instead, it’s better to call save with commit=False. The Django docs explain this in depth, but here’s a quick example:

new_object = form.save(commit=False)
new_object.name = 'Whatever'
new_object.save()

By calling save with commit=False, you get an object back. You can do whatever you want with this object, but make sure to save it once you make your changes!

Leave a comment