Skip to content

Instantly share code, notes, and snippets.

@chriskief
Last active October 19, 2018 08:57

Revisions

  1. chriskief revised this gist Jan 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion query.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    ids = [9, 8, 1, 2, 7, 3]
    addons = Model.objects.filter(id__in=ids).extra(
    results = Model.objects.filter(id__in=ids).extra(
    select={'manual': 'FIELD(id,%s)' % ','.join(map(str, ids))},
    order_by=['manual']
    )
  2. chriskief revised this gist Jan 13, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion query.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    ids = [9, 8, 1, 2, 7, 3]
    addons = Model.objects.filter(id__in=ids).extra(
    select={'manual': 'FIELD(id,%s)' % ','.join(map(str, ids))},
    order_by=['manual'])
    order_by=['manual']
    )
  3. chriskief revised this gist Jan 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion query.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ids = [a_list, of, ordered, ids]
    ids = [9, 8, 1, 2, 7, 3]
    addons = Model.objects.filter(id__in=ids).extra(
    select={'manual': 'FIELD(id,%s)' % ','.join(map(str, ids))},
    order_by=['manual'])
  4. chriskief created this gist Jan 13, 2015.
    4 changes: 4 additions & 0 deletions query.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    ids = [a_list, of, ordered, ids]
    addons = Model.objects.filter(id__in=ids).extra(
    select={'manual': 'FIELD(id,%s)' % ','.join(map(str, ids))},
    order_by=['manual'])