[英]how can i get always data based on the logged user?
I'm Working with Django / Rest Framework and I have multiple applications and I would like to avoid repeaters in my situation, I would like to get the logged user data without repeating this line each time:我正在使用 Django / Rest 框架,我有多个应用程序,我想在我的情况下避免重复,我想获取记录的用户数据,而不是每次都重复这一行:
queryset = queryset.filter(user = self.request.user)
Fixed by reading more in the documentation:通过阅读文档中的更多内容来修复:
def get_queryset(self):
"""
This view should return a list of all the purchases
for the currently authenticated user.
"""
user = self.request.user
return Contact.objects.filter(user=user)
and i started called the get_queryset()
like that self.get_queryset()
我开始像
get_queryset()
那样self.get_queryset()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.