I think this would work:
Comment.objects.filter(*[
~Q(id__in=user.comments.order_by('-created')[3:].values_list('id', flat=True))
for user in User.objects.all()
])
However, this does not look like pythons or an effective way to solve the problem. (The performance issue can be resolved with a cache, but still.)
, ? . , -created:
{% for user in users %}
{% for comment in user.comments.all|slice:"3" %}{{ comment }}{% endfor %}
{% endfor %}
LIMIT SQL-, . , , , .
, . , , .
SQL
, , SQL ([1] ), extra() - ([2] - , ).
[1] ?
[2] django.extra( = clauses clobbered .filter(foo__in =... subselects