Answer the question
In order to leave comments, you need to log in
How to correctly form a QuerySet query to get several nested objects from each object?
For example, there is a list of category IDs = [56, 67, 59]
How to correctly form QS so that in one query to the database to get 5 posts of each of these categories?
Now I have this:
def test(self):
categories = [56, 67, 59]
queryset = Post.objects.filter(
category__in=categories).distinct()[:15]
return queryset
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question