Skip to content

Instantly share code, notes, and snippets.

@mperlet
Created June 26, 2014 13:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mperlet/5605c70f8ad1c129b4b6 to your computer and use it in GitHub Desktop.
Save mperlet/5605c70f8ad1c129b4b6 to your computer and use it in GitHub Desktop.
Converts a list to a django queryset
def list_to_queryset(model_list):
if len(model_list) > 0:
return model_list[0].__class__.objects.filter(
pk__in=[obj.pk for obj in model_list])
else:
return []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment