-
Do not forget about type annotation in class methods.
-
You do not need
.all()
method before.prefetch_related()
and.select_related()
methods:
Good example:
queryset = Movie.objects.prefetch_related("actors")
Bad example:
queryset = Movie.objects.all().prefetch_related("actors")
- You can provide multiple arguments into prefetch_related method:
Good example:
queryset = Movie.objects.prefetch_related("actors", "genres")
Bad example:
queryset = Movie.objects.prefetch_related("actors").prefetch_related("genres")
Add comments, prints, and functions to check your solution when you write your code. Don't forget to delete them when you are ready to commit and push your code.