Tuesday, September 27, 2011

Re: commit=false and user id

On Tue, Sep 27, 2011 at 4:15 PM, David <cthlogs@gmail.com> wrote:
> Hi Tom
>
> I had been using ajax on the form and thus hadn't got my traceback. I
> removed all ajax to get the traceback and it says:
>
> 'WSGIRequest' object has no attribute 'person'
>
> Relating to:
>
> f.person = request.person
>
> I guess. Do I have to add a hidden field for the person id?
>

In your first post you say that this is one user (request.user)
updating a page about a different user (person).

Normally (and again, this is hard to see as you don't show your form,
or the view which initially creates the form), the 'person' would be
inferred from the URL (eg "/foo/bar/update-user/12345" to update user
with id 12345), and the view which handles the submission of the form
either receives that as a hidden form field, or it also extracts it
from the URL.

It's also much more common to have the initial view and the handling
view as the same view.

So, do you omit the person field from your ModelForm? If so, don't;
instead make sure that you pass initial={'person': person} when you
create that form, and the value will be passed through correctly.

Cheers

Tom

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment