0

What i want to do is to filter the queryset for every action on the resource by the authenticated user's ID which is a foreign key on the model, how can I read it when defining the query set?

class RunSessionViewSet(viewsets.ModelViewSet):

    """API endpoint for listing and creating sprints."""
    queryset = RunningSession.objects.order_by('createdDate')
    serializer_class = RunSessionSerializer
1
  • you can't do it in class definition , override get_queryset() method Commented Aug 11, 2016 at 12:18

1 Answer 1

4

You should override get_queryset() method as described in the docs

def get_queryset(self):
    user = self.request.user
    return RunningSession.objects.filter(foreignkey_field=user).order_by('createdDate')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.