The Great Magnet. What a fool I was to defy him.

Python / Django — Combine Querysets and Sort. Sort List of Any Objects.

October 6, 2009 · Leave a Comment

Assuming it quacks like a duck, you can use operator.attrgetter()

Combine queryset by turning it into a list:
queryset_list = list(queryset1).extend(list(queryset2))

Sort the list by:
sorted_list = queryset_list.sort(key=operator.attrgetter(‘attribute to sort by’))

Categories: Life

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment