Extract children with a given condition - Django MPTT and Django rest framework

Viewed 74

enter image description here

In this tree I want to do a query so that only the first generation of the red circle is extracted. But the condition is that the value of each circle must be greater than zero, ie the green circles:

enter image description here

Serializers:

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

View:

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

Certainly result is [5(1,0,3)] that is not desirable. How can I do this query?

0 Answers
Related