Last active
August 29, 2015 14:01
-
-
Save andybak/033ea14fe76d6ec0e0a7 to your computer and use it in GitHub Desktop.
This file contains 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
# Version 1 | |
return Response(dict([( | |
int(pk), | |
{'lowest_stock': ItemModel.objects.get(id=int(pk)) \ | |
.get_lowest_stock_for_subbooking(subbooking)} | |
) for pk in request.QUERY_PARAMS.get('item_models', '').split(',')])) | |
# Version 2 | |
result = dict() | |
pks = [int(pk) for pk in request.QUERY_PARAMS.get('item_models', '').split(',')] | |
models = ItemModel.objects.filter(id__in=pks) | |
for m in models: | |
result[m.pk] = {'lowest_stock': m.get_lowest_stock_for_subbooking(subbooking)} | |
return Response(result) | |
# Version 3 | |
pks = [int(pk) for pk in request.QUERY_PARAMS.get('item_models', '').split(',')] | |
models = ItemModel.objects.filter(id__in=pks) | |
result = {m.pk: {'lowest_stock': m.get_lowest_stock_for_subbooking(subbooking)} for m in models} | |
return Response(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment