[Answered ]-It is good practice to get all object in RetrieveUpdateDestroy Method?

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 Students.

Leave a comment