[Answered ]-Django get values from field after order_by

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'))
}

Leave a comment