0

在此处输入图像描述

在这棵树中,我想做一个查询,以便提取第一代红色圆圈。但条件是每个圆圈的值必须大于零,即绿色圆圈:

在此处输入图像描述

序列化器:

class CircleBaseSerializer(serializers.ModelSerializer):
    class Meta:
        model = Circle
        fields = ('id', 'value')


class CircleChildrenSerializer(CircleBaseSerializer):
    class Meta(CircleBaseSerializer.Meta):
        pass

class CircleParentSerializer(CircleBaseSerializer):
    children = CircleChildrenSerializer(many=True)
    class Meta(CircleBaseSerializer.Meta):
       pass

看法:

class CircleViewSet(ReadOnlyModelViewSet):
    serializer_class = CircleParentSerializer
    queryset = Circle.objects.all()
    def get_queryset(self):
        id = self.kwargs["id"]
        u=Circle.objects.get(pk=id)

当然结果是 [5(1,0,3)] 是不可取的。我该怎么做这个查询?

4

0 回答 0