On Sun, 2009-03-08 at 17:15 -0700, AlexK wrote:
[...]
> 
> To make it a bit easier to view the code, i'll use dpaste:
> Models
> http://dpaste.com/hold/10157/
> Views
> http://dpaste.com/hold/10159/
> Template
> http://dpaste.com/hold/10160/

That template looks very scary. It would be very uncommon to need to
have different form displays for GET or POST actions. You should really
be aiming to display the same form every time, just with some
information filled in if the form is being re-displayed due to errors.
None of the examples in the Django forms documentation has a template
anything like that and you should be able to come up with something
almost identical to those examples.

[...]
> I think I can sort out submitting these two forms at once based on
> your advice,

You mean processing the (one) HTML form submission into two Django forms
(unfortunately "form" is an overloaded word here). You seem to be on the
right track there.

Your code there is a little fragile, since you only test
c_form.is_valid() and not q_form.is_valid(). You have to check both,
since otherwise errors in q_form won't be handled properly and c_form
will be saved even if the submitted data isn't entirely valid.

>  but how do I manage the M2M field with submission? When I
> use a combo list it only returns a 2 or something silly. Can you give
> an example of how to manage this kind of field?

Well, a "2" isn't necessarily silly. It depends on how you're
constructing the widget, but each choice in the combo box will have a
value (which is different from the display string that is shown to the
user in the browser). When the form is submitted, all those values will
be returned -- not the display strings, since you already know what they
are and the idea is to send as little information as possible between
the browser and the server (plus the display string can vary, if say the
language changes, whereas the value will always be the same). So the "2"
you are seeing is one of the values.

It sounds like you want a MultipleChoiceField or even a ModelChoiceField
(the latter is used automatically with modelforms -- again, have a look
at whether they meet your requirements for one or other of your forms).

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to