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

Performing actual queries in get_queryset method #42

Open
giulioindev opened this issue Aug 6, 2024 · 1 comment
Open

Performing actual queries in get_queryset method #42

giulioindev opened this issue Aug 6, 2024 · 1 comment

Comments

@giulioindev
Copy link

I need to call the following url: users/:user_pk/photos/:photo_pk/

To get only the photos related to the user having id=user_pk if the user exists, I have to extend the get_queryset method to be able to raise NotFound exception if no user with id=user_pk exists.

Which is the best way to manage it since I'm performing a query on the DB and the get_queryset method is only sync in GenericAPIView, GenericViewSet, etc?

@G4DavidAlmeida
Copy link

My understanding is, get_queryset is not the place you should do that, you should just set the photo_id and user_id in queryset.

If you can provide a example code or be more specific about your case, i can provide a more accurate solution

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