djangodjango-admindjango-users

Get current user log in signal in Django


I am just using the admin site in Django. I have 2 Django signals (pre_save and post_save). I would like to have the username of the current user. How would I do that? It does not seem I can send a request Or I did not understand it.

Thanks


Solution

  • If you are using the admin site why not use a custom model admin

    class MyModelAdmin( admin.ModelAdmin ):
        def save_model( self, request, obj, form, change ):
            #pre save stuff here
            obj.save()
            #post save stuff here
    
    
    
    admin.site.register( MyModel, MyModelAdmin )
    

    A signal is something that is fired every time the object is saved regardless of if it is being done by the admin or some process that isn't tied to a request and isn't really an appropriate place to be doing request based actions