Skip to content

Instantly share code, notes, and snippets.

@ltvolks
Created May 28, 2012 22:28
Show Gist options
  • Select an option

  • Save ltvolks/2821469 to your computer and use it in GitHub Desktop.

Select an option

Save ltvolks/2821469 to your computer and use it in GitHub Desktop.
Combine results from separate Django querysets linearly
# Combine results from separate Django querysets linearly
from itertools import chain
good_ids = (2,8,13,11,22,42,56,61,46)
good = Money.filter(id__in=good_ids).order_by('id')
bad = Money.exclude(id__in=good_ids)
# Throwing good money after bad
money = list(chain(bad, good))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment