Django: Get current user in model save

后端 未结 6 1584
既然无缘
既然无缘 2020-12-04 23:29

I want to get the currently logged in user (request.user) in the save method of models.py. I want to check the role of the user and see if it can p

6条回答
  •  有刺的猬
    2020-12-05 00:03

    You can tackle this problem from another angle. Instead of changing the models save method you should override the AdminSites save_model method. There you'll have the request object and can access the logged in user data as you already pointed out.

    Have a look at this chapter of the docs: Django ModelAdmin documentation save_model

提交回复
热议问题