Changes between Version 1 and Version 2 of Ticket #26780, comment 9
- Timestamp:
- Apr 20, 2018, 11:53:08 AM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #26780, comment 9
v1 v2 3 3 from django.db.models import OuterRef, Subquery 4 4 5 User.objects.all().prefetch_related('comments',queryset=Comment.objects.filter(id__in=Subquery(Comment.objects.filter(user_id=OuterRef('user_id')).values_list('id', flat=True)[:5]))) 5 `User.objects.all().prefetch_related('comments',queryset=Comment.objects.filter(id__in=Subquery(Comment.objects.filter(user_id=OuterRef('user_id')).values_list('id', flat=True)[:5])))`