m.objects.filter(id__in=[3,1,8])
ids = [3,1,8]
result = sorted(m.objects.filter(id__in=ids), key=lambda i: ids.index(i.pk))
ids = [3,1,8]
conditions = Case(*[When(pk=pk, then=n) for n, pk in enumerate(ids)])
queryset = m.objects.filter(id__in=ids).order_by(conditions)