You could do for example:

exclude the user field from the form and in your view something like this:

form = YourModelForm(request.POST)  #fill the modelform with the data
        if form.is_valid(): # check if valid
mynewobject = form.save(commit=False) #save it to create the object but dont send to database
            mynewobject.user = request.user # attach the user to it
mynewobject.save() # now do the real save and send it to the database

Am 20.02.2012 22:59, schrieb ds39:
I hate to keep bringing this issue up, but I'm still not entirely sure
how to implement this. I've tried a number of different ways to
connect some kind of user ID with form data without much success. Is
the idea that after authenticating the user in the view, request.user
be set to some variable that allows the user ID to be added to the
model or ModelForm ? Would this make the user object associated with
the form or model object accessible by filtering in the API ?

Thanks again


On Feb 19, 9:48 pm, Shawn Milochik<sh...@milochik.com>  wrote:
On 02/19/2012 09:29 PM, ds39 wrote:

Thanks for your response. But, would you mind expanding on it a little
bit ?
How about you give it a try and see what you can figure out? In your
view, request.user will return the currently logged-in user (or an
AnonymousUser if they're not logged in). Since you said your view
requires login, you'll have a User object all ready to go.

Shawn

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