Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 22 lines (15 sloc) 0.51 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import zlib


# TODO(davedash): liberate this
def manual_order(qs, pks, pk_name='id'):
    """
Given a query set and a list of primary keys, return a set of objects from
the query set in that exact order.
"""

    if not pks:
        return qs.none()

    objects = qs.filter(id__in=pks).extra(
            select={'_manual': 'FIELD(%s, %s)'
                % (pk_name, ','.join(map(str, pks)))},
            order_by=['_manual'])

    return objects


crc32 = lambda x: zlib.crc32(x) & 0xffffffff
Something went wrong with that request. Please try again.