Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify a recursivity depth #11

Closed
achedeuzot opened this issue May 10, 2016 · 6 comments
Closed

Specify a recursivity depth #11

achedeuzot opened this issue May 10, 2016 · 6 comments

Comments

@achedeuzot
Copy link

Hi !
Thanks for this great plugin for django rest framework. Is there any way to specify the depth of the recursion ?
I tried using the class Meta depth attribute but I don't think the field uses it. What would be the best approach to this ?
Best regards,

@heywbj
Copy link
Owner

heywbj commented May 10, 2016

This is not currently supported. I would suggest pruning the dataset before you try to serialize it. If you are deserializing something, then you could deserialize it and then prune.

@achedeuzot
Copy link
Author

achedeuzot commented May 10, 2016

I'm using it on a ModelViewset/ModelSerializer so I don't know how I could prune it ?
There is no queryset or get_queryset method in the arguments of the field...

@heywbj
Copy link
Owner

heywbj commented May 11, 2016

Can you set the queryset in the ModelViewSet?

@achedeuzot
Copy link
Author

No... My datastructure is really simple:

# models.py
class Node(models.Model):
    parent = models.ForeignKey('self', related_name='children')

# api.py
class NodeSerializer(serializers.HyperlinkedModelSerializer):

    parent = serializers.HyperlinkedRelatedField(
        view_name='api:parameter-detail',
        queryset=Node.objects.all(),
    )
    children = RecursiveField(many=True, allow_null=True)

    class Meta:
        model = Node
        fields = ('parent', 'children')
        depth = 2

class NodeViewSet(viewsets.ModelViewSet):
    queryset = Node.objects.all()

I cannot prune or filter the queryset. It will depend on which initial node is requested. I need to limit the depth of the RecursiveField only... Or maybe I'm missing something ?

@heywbj
Copy link
Owner

heywbj commented May 13, 2016

You could look in to the django treebeard package for a tree with more features. Or django mptt. I believe there are probably others as well.

Or I suppose you could extend the recursive field to add the functionality your desire

@achedeuzot
Copy link
Author

I'll just extend the recursive field to add the functionality I need. Both mptt and treabeard have limitations or defaults that don't work with my project.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants