1π
Why [do] we need to get all object[s] in [a]
RetrieveUpdateDestroy
[view]?
We donβt: the queryset is not evaluated. This is only used as a "parent" queryset to make querysets to retrieve, update, and delete a single object.
Indeed, for a retrieve
method, it will add .get(pk=some_pk)
at the end, and thus make a query to retrieve that single object.
The queryset can be used to filter certain items, to prevent retrieving, updating and removing certain objects for example. You can for example use queryset = Student.objects.filter(active=True)
to only be able to retrieve active Student
s.
Source:stackexchange.com