开发者

Django-Get Current User In Save Time

开发者 https://www.devze.com 2023-04-03 08:03 出处:网络
How Can I Get Current User When I Want Save Som开发者_如何转开发ething In Django Admin. I Mean When Overriding Save Method???How do you mean? Do you always want to get current user when you override t

How Can I Get Current User When I Want Save Som开发者_如何转开发ething In Django Admin. I Mean When Overriding Save Method???


How do you mean? Do you always want to get current user when you override the Model.save() method, or when you save in Admin?

If you override the ModelAdmin.save_model(...) method you have access to the request, and thus the request.user, which is current user.

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model

0

精彩评论

暂无评论...
验证码 换一张
取 消