1

When using a model form:

>>> honest_man.name
u'Abe Lincoln'
>>> form = PersonForm({'name': u'Barack'}, instance=honest_man)
>>> if form.is_valid():
...     print('Yay!')
...     bankster = form.save()
... else:
...     print('Uh Oh :(')
...
Uh Oh :(
>>> honest_man.name  # So, we'll just check to be sure nothing changed
u'Barack'
>>> # Oh no, our instance has been corrupted. Now I have to query for it to get
>>> # a clean version without the changes the form made.
>>> honest_man = Person.objects.get(name=u'Abe Lincoln')
>>> # Wasted query because I still need the instance

Is there a way to avoid this (I'm using Django 1.3)?

1
  • The political undertone of your question might upset some people.
    – jammon
    Apr 8, 2011 at 4:52

1 Answer 1

1

No, this can't be avoided in 1.3 because of model validation. After cleaning of form fields ModelForm populates instance's fields with cleaned data and calls instance.clean_fields() and instance.clean() methods.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.