views:

17

answers:

1

Hi all,

I have a similar problem as a previously solved problem of mine, except this time solution doesn't seem to work:

http://stackoverflow.com/questions/2991365/how-to-auto-insert-the-current-user-when-creating-an-object-in-django-admin

Previously i used to override the save_model to stamp the user submitting the article. Now i need to do the same for comments, it doesn't seem to work anymore.

Anyone have any ideas?

Thanks a lot!

Jason

A: 

The saving isn't done in the InlineAdmin's save_form, you have to look at save_formsets in the ModelAdmin to which the inlines belong:

 class MyAdmin(admin.ModelAdmin):
    inlines = [MyInlineAdmin,.....]

    def save_formset(self, request, form, formset, change):
        formset.save()
        if not change:
            for f in formset.forms:
                obj = f.instance 
                obj.user = request.user
                obj.save()
lazerscience
Thanks a lot! Just to provide some more substantial example: http://stackoverflow.com/questions/1477319/how-to-get-the-django-current-login-user
FurtiveFelon