在这棵树中,我想做一个查询,以便只提取第一代红色圆圈。但条件是每个圆圈的值必须大于零,即绿色圆圈:
序列化器:
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)] 是不可取的。我该怎么做这个查询?