I found that ModelForm in Django is very easy to use and saves development time.
However, I was stuck when I realized that is_valid actually saves ModelForm! I would like to know if this is the expected behavior, or am I doing something wrong?
What is happening to me,
form=SOME_MODEL_FORM(...., instance=cafe)
print cafe.name
if request.method="POST":
if form.is_valid():
print cafe.name
I use post_save for debugging, is_valid really saved the model!
My current workaround is to save the model in another object before calling is_valid, and then save it back to override the chang. This is really a hack, and I would like to have a more elegant way to achieve the same goal (not save the model after calling is_valid).
Thank!
source
share