Created
June 26, 2014 13:54
-
-
Save mperlet/5605c70f8ad1c129b4b6 to your computer and use it in GitHub Desktop.
Converts a list to a django queryset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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