我是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)