Is it possible to get the dictionary while query on Django Model instead of list of objects??
For example:
ids = [1, 2, 3, 4, 5]
objs = someModel.objects.filter(pk__in = ids)
It returns me list of objects. What i want is somehow if i can, i want dictionary of objects with primary key as key.
objs = {1: query_object, 2: quer_object, 3: quer_object, 4: quer_object, 5: quer_object}
Use a dict comprehension ( http://docs.python.org/reference/expressions.html#grammar-token-dict_comprehension – available in python 2.7.2 and possibly earlier):
Apart from being more explicit and compact, this avoids the creation of an intermediate list or generator object.