Django 访问自定义管理器中登录的用户
我想在我编写的自定义管理器中访问当前登录的用户。我想这样做,以便我可以过滤结果以仅显示他们有权访问的对象。
无论如何,是否可以在不实际传递它的情况下执行此操作?类似于它在视图中的工作方式,您可以在其中执行 request.user。
谢谢
I want to access the currently logged in user in a custom manager I have wrote. I want to do this so that I can filter down results to only show objects they have access to.
Is there anyway of doing this without actually passing it in? Something similar to how it works in views where you can do request.user.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不传递它,我见过的最好的方法是使用中间件(在 这个 StackOverflow 问题,我将复制/粘贴以便于参考):
中间件:
经理:
Without passing it in, the best way I've seen is to use a middleware (described in this StackOverflow question, I'll copy/paste for ease of reference):
Middleware:
Manager: