Accessing queryset in serializer

35 views
Skip to first unread message

Mathias Nielsen

unread,
Jun 28, 2019, 8:41:22 AM6/28/19
to Django REST framework
Hi
I am trying do use this approach https://medium.com/quant-five/speed-up-django-nested-foreign-key-serializers-w-prefetch-related-ae7981719d3f#04cf to handle nested relationship. We have a lot of those and I would like to automate the handling of these as much as possible.

The linked solution is okay, but involves calling that method in all views and that is just a lot of extra work. The serializer has access to all the information needed to perform this task I think, but I cannot get access to the queryset in order to actually make the changes.

For context: I am building a custom serializer that inherits from ModelSerializer, that is to be used whenever this kind of behavior is required.

Can someone point me to a place where I can intercept (and change) the queryset on the serializer instance?

Alan Crosswell

unread,
Jun 28, 2019, 9:30:47 AM6/28/19
to django-res...@googlegroups.com
Not sure this is useful, but https://django-rest-framework-json-api.readthedocs.io/en/stable/ has this already by default. This assumes you want to use jsonapi.org serialization....

--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/82538816-1454-479c-b944-6dbd82686295%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Alan Crosswell
Associate VP & CTO

Reply all
Reply to author
Forward
0 new messages