Skip to content

Instantly share code, notes, and snippets.

@chriskief
Last active October 19, 2018 08:57
Show Gist options
  • Save chriskief/03c09d4bc11a0b100c8f to your computer and use it in GitHub Desktop.
Save chriskief/03c09d4bc11a0b100c8f to your computer and use it in GitHub Desktop.
ids = [9, 8, 1, 2, 7, 3]
results = Model.objects.filter(id__in=ids).extra(
select={'manual': 'FIELD(id,%s)' % ','.join(map(str, ids))},
order_by=['manual']
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment