order_by() doesn't work with filter() in Django view

I've done lots of .filter().order_by() chains just as you have them there, and nothing jumps out to me as out of place. I've never tried to carry that ordering over to the template without further processing the objects though (usually iterate over them), so I wonder if the order_by() is lost as part of django's lazy evaluation? Maybe try wrapping the filter().order_by() line in a list() to force evaluation there instead of it being put off till some later time?

bilder = list(Bild.objects.filter(album__id = album_id).order_by('slot'))

It is a shot in the dark, but quick enough to be worth a try.


You should try to order by slot__id.

Like this:

bilder = Bild.objects.filter(album__id = album_id).order_by('slot__id')

Tags:

Django