Junior — Senior
Getting groups with more than ten posts
livecode
Task condition
In the context of a Django project, it is required to write a function that returns a set of groups. There are two models — Group and Post, related by a many-to-many relationship (one group can contain many posts). It is necessary to select only those groups where the number of related posts exceeds 10. An example of a function template:
def most_popular_groups(request):
# List groups (Group) where the number of posts (posts) is greater than 10
popular_groups = ...
return render(request, "groups.html", {"groups": popular_groups})
Inside the function, you should form a query that counts the number of posts for each group and selects groups with a post count > 10, then pass the resulting QuerySet to the "groups.html" template.