#6022: m2m ValueError with form_for_instance on fresh instance
---------------------------+------------------------------------------------
Reporter: sjulean | Owner: nobody
Status: new | Component: django.newforms
Version: newforms-admin | Keywords: m2m form_for_instance
Stage: Unreviewed | Has_patch: 0
---------------------------+------------------------------------------------
Assume !MyModel is a model with an m2m field. I tried this:
{{{
my_instance = MyModel(some_fk=some_value)
MyModelForm = forms.form_for_instance(my_instance)
}}}
What I got was a !ValueError telling me that i can't access m2m fields of
instances that aren't saved - this was caused by a call of
value_from_object from newforms/models.py:119 (in newforms-admin r6710).
Wrapping the value_from_object call in a "try ... except !ValueError:
current_value = None" seems to have done the trick. However, I haven't
submitted this as a patch, because it doesn't smell quite right. Is this
the right solution? Or should value_for_object return something other than
an exception for unavailable m2m field values?
--
Ticket URL: <http://code.djangoproject.com/ticket/6022>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---