How does this solve the problem of having two related objects that have the
same attribute name (like "name") on the same html form? As I see it, it
doesn't. There will be a conflict and it will be impossible to keep them
separate.
IOW,
<form ... >
{{ account_form }}
{{ contact_form }}
<input type="submit">
</form>
def update_account_and_contact
if(request.POST)
account_form = AccountForm(request.POST,
instance=get_object_or_404(Account, id=request.POST['id'])
contact_form = ContactForm(request.POST,
instance=get_object_or_404(Contact, id=request.POST['id'])
if(account_form.is_valid() && contact_form.is_valid())
account_form.save()
contact_form.save()
.....
The rails solution is much superior.
On Dec 19, 2009, at 2:15 AM, Jani Tiainen wrote:
> <input name="foo" value="one">
> <input name="foo" value="two">
>
> Result is stored in request.POST (or you can do same with get params,
> ?foo=one&foo=two).
>
> for example request.POST.getlist('foo'). Default getitem implementation
> returns only last occurence from list.
>
> See:
> http://docs.djangoproject.com/en/1.1/ref/request-response/#querydict-objects
> for more info.
>
> On Sat, Dec 19, 2009 at 2:27 AM, Todd Blanchard <[email protected]> wrote:
> One thing I'm keenly missing from rails is the form input naming convention
> that causes the form values to be converted into a hierarchy. For instance,
>
> <input name="foo[bar]" value"one">
> <input name="foo[baz]" value="two">
>
> will result in the request values being stored as { 'foo' : {'bar' : 'one',
> 'baz' : 'two' }}
>
> this is very handy when updating multiple related objects in a single form
> submit.
>
> Is there a similar facility for django/python or will I need to write it?
>
> -Todd Blanchard
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" 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-users?hl=en.
>
>
>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" 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-users?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Django users" 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-users?hl=en.