On 1/14/07, James Tauber <[EMAIL PROTECTED]> wrote:

On 14/01/2007, at 10:29 AM, Honza Kr l wrote:

> On 1/14/07, James Tauber <[EMAIL PROTECTED]> wrote:
>>
>> I have a model with a required field of ForeignKey(User)
>>
>> What's the easiest way to write an add manipulator that automatically
>> provides the current authenticated user for that field?
>
> do not write it at all, use generic views and wrap it in your function
> that will supply the user

I'm not sure what you mean - can you give a code snippet?

others have done this better than me:
http://www.b-list.org/weblog/2006/11/16/django-tips-get-most-out-generic-views

I somtimes do:
if request.POST:
 post - request.POST.copy()
 post[ 'some_field' ] = my_value
 request.POST = post

return update_object( request, ..... )


I'm currently using a custom view because the form is on a page with
a bunch of other stuff. It's primarily a list of existing objects,
filtered by the current user, with a form for adding a new one.
Perhaps this can still be done with a generic view.

I currently have a view that contains, amongst other things:

     if request.method == "POST":
         new_data = request.POST.copy()
         errors = manipulator.get_validation_errors(new_data)

         if not errors:
             manipulator.do_html2python(new_data)
             new_object = manipulator.save(new_data)

             ...
     ...

But I can't see how I can inject the user in here unless I do
something like: write a custom manipulator that doesn't have the
requirement for the user foreign key and then pass in the user
somehow into the manipulator (via new_data?)

forget about manipulators, they are dead, use newforms, its cooler ;)


James


>



--
Honza Kr l
E-Mail: [EMAIL PROTECTED]
ICQ#:   107471613
Phone:  +420 606 678585

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to