Get current user log in signal in Django

后端 未结 6 1766
忘掉有多难
忘掉有多难 2021-02-05 10:01

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 n

6条回答
  •  我在风中等你
    2021-02-05 10:23

    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

提交回复
热议问题