[portland] django helper

Dylan Reinhardt python at dylanreinhardt.com
Wed Apr 8 20:23:36 CEST 2009


This is a common question for Django.  The challenge here is that
request.user is known to the view, but not to the model... so you can't just
make request.user the default value on the model.

Take a look at this and browse down to "The Holy Grail":
http://www.b-list.org/weblog/2006/nov/02/django-tips-auto-populated-fields/

HTH,

Dylan



On Wed, Apr 8, 2009 at 11:08 AM, Patrick Curtain <pcurtain at gmail.com> wrote:

> Hey!
>
> > There's a few of us here who work on Django.  If you have specific
> > questions, you could probably get several responses.  Some might even be
> > helpful.  :-)
>
> I'll start here then, for now.  :)  Thanks!  Anyone else, feel free to
> tell me it's too specific for the pdxpython list.
>
> I've got a 'Recipe' model that needs to store the author.  From what I
> could learn in other examples, this got added to my model:
>
>    member = models.ForeignKey(User, related_name="added_recipes",
> blank=True, null=True)
>
> When I view the form in the admin interface, it works, but that field
> shows up as a select box of all users in the system.
>
> My goal is to let some bulk data entry happen in advance of the full
> app being completed.  Hence the push to make it work in admin and get
> going.
>
> Question:
>
> How do I tell the admin interface form (via the internal 'class Admin'
> magic ideally) that it should get the user from the 'request.user'
> currently using the app?
>
> Responses of "dumb idea, do this instead" -just- as welcome.  :)
>
> And thanks, everyone!
> --p
> _______________________________________________
> Portland mailing list
> Portland at python.org
> http://mail.python.org/mailman/listinfo/portland
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/portland/attachments/20090408/4abf61e3/attachment.htm>


More information about the Portland mailing list