Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

23 lines (15 sloc) 0.51 kb
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
Jump to Line
Something went wrong with that request. Please try again.