[portland] django helper
Jeff Schwaber
freyley at gmail.com
Wed Apr 8 20:38:21 CEST 2009
On Wed, Apr 8, 2009 at 11:08 AM, Patrick Curtain <pcurtain at gmail.com> wrote:
> Hey!
>
>
> 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.
>
> 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?
>
Most of what I've seen to try to do this isn't to set a default, it's to
make it happen invisibly. For example, this:
class ArticleAdmin(admin.ModelAdmin):
exclude = ('member',)
def save_model(self, request, obj, form, change):
obj.member = request.user
obj.save()
But looking at the doc, save_formset might do what you want:
http://docs.djangoproject.com/en/1.0//ref/contrib/admin/#ref-contrib-admin
Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/portland/attachments/20090408/c41c41da/attachment.htm>
More information about the Portland
mailing list