On Aug 4, 12:34 pm, tow <toby.o.h.wh...@googlemail.com> wrote:
> In the ModelForm documentation (https://docs.djangoproject.com/en/dev/
> topics/forms/modelforms/) the following snippet appears:
>
> # Create a form to edit an existing Article.
>
> >>> a = Article.objects.get(pk=1)
> >>> f = ArticleForm(instance=a)
> >>> f.save()
>
> I may be doing something wrong, but I can't see how that should work
> in Django's current codebase.
>
> The save() method eventually calls save_m2m(), and at forms/models.py:
> 77 Django tries to get at f.cleaned_data - which doesn't exist,
> because the form hasn't been validated yet.

And it indeed raises the expected AttributeError at the expected
place.

> Even if the form had been validated, the validation would have failed,

which is actually the case.

> because Django thinks this is an unbound form. I don't know whether
> that's correct or not - it's been bound to an initial instance if not
> to new data.

"bound form" means "bound to (presumably POST or GET) data.


> Either way, I can't see what the snippet above is trying to tell me.
> Can someone help me?

This particular snippet is about how to prepare a ModelForm to edit an
existance model instance, that is, the code you would use in a typical
yourmodel_edit(request, yourmodel_id) view, when the request.method is
not "POST". IOW, it's actually  a form intended to be rendered in a
template, and the "f.save()" in the example should be "print f".

My 2 cents...


> Thanks,
> Toby

-- 
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