以下代码中(qs | qs1)的含义是什么?

时间:2019-08-28 12:09:14

标签: python django

我是Django的新手。以下代码的总体逻辑是什么?仍然(qs | qs1)在Python / Django中到底意味着什么?

class TweetDetailAPIView(generics.ListAPIView):
    queryset = Tweet.objects.all()
    serializer_class  = TweetModelSerializer
    pagination_class = StandardResultsPagination
    permission_classes = [permissions.AllowAny]

    def get_queryset(self, *args, **kwargs):
        tweet_id = self.kwargs.get("pk")
        qs = Tweet.objects.filter(pk=tweet_id)
        if qs.exists() and qs.count() == 1:
            parent_obj = qs.first()
            qs1 = parent_obj.get_children()
            qs = (qs | qs1).distinct().extra(select={"parent_id_null": 'parent_id IS NULL'})
        return qs.order_by("parent_id_null", '-timestamp')
        the_parent = self
        if self.parent:
            the_parent = self.parent
        return the_parent

    def get_children(self):
        parent = self.get_parent()
        qs = Tweet.object.filter(parent=parent)
        qs_parent = Tweet.objects.filter(pk.parent.pk)
        return (qs | qs_parent)

1 个答案:

答案 0 :(得分:0)

这是两个查询集之间的OR运算。查看documentation了解更多信息。