views:

19

answers:

1

Let say I have a django ModelForm which I want to edit before saving.

For example,

Instead of this

model_instance = form.save()

I would like to do something like this

model_instance = form.get_model()
model_instance.edit() #say add a new field which is not available on form
model_instance.save()
+4  A: 
model_instance = form.save(commit=False)

will return you a object of the model without saving to the DB

you can then add value of some field which is not available on form

model_instance.some_field = value
model_instance.save()
Ashok
I just found it somewhere and was on my way to add the answer myself. :)
Owais Lone