下面的方法返回我关注的用户帖子的查询集
def get_queryset(self, *args, **kwargs):
# returns the users that i follow
following_users = self.request.user.profile.get_following()
#gets posts of following users
qs = Tweet.objects.filter(user__in=following_users).order_by("-timestamp")
return qs
我想在这个查询集中添加我自己的帖子。如何在此查询集中添加我自己的用户?
像这样:
def get_queryset(self, *args, **kwargs):
# returns the users that i follow
following_users = self.request.user.profile.get_following()
following_users.append(self.request.user) # This is not working
#gets posts of following users
qs = Tweet.objects.filter(user__in=following_users).order_by("-timestamp")
return qs
类似这样的内容>;我该怎么做
我求求你帮忙
这不起作用的原因是
get_following()
很可能返回一个QuerySet
,而不是一个列表,并且不能附加到Queryset
很可能只使用析取条件更容易实现:
您需要使用Q objects,因此您可以从您关注的用户或您自己那里查找帖子
相关问题 更多 >
编程相关推荐