-
-
Save gaozhidf/8e871b2182d18f8470e9e45ffbc7326c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
from: https://chriskief.com/2015/01/13/sort-django-query-order-by-using-values-within-in/