1👍
✅
You can post-process the data with the groupby(…)
function [python-doc] of the itertools
module [python-doc]:
from itertools import groupby
from operator import attrgetter
qs = Course.objects.all().order_by('instructor')
result = {
k: list(vs)
for k, vs in groupby(qs, attrgetter('instructor'))
}
Source:stackexchange.com