QuerySets in Dictionaries

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Nov 12 20:55:57 EST 2009


On Thu, 12 Nov 2009 10:39:33 -0800, scoopseven wrote:

> I need to create a dictionary of querysets.  I have code that looks
> like:
> 
> query1 = Myobject.objects.filter(status=1) 
> query2 = Myobject.objects.filter(status=2) 
> query3 = Myobject.objects.filter(status=3)
> 
> d={}
> d['a'] = query1
> d['b'] = query2
> d['c'] = query3
> 
> Is there a way to do this that I'm missing?

I don't understand your problem. Assuming Myobject is defined, and has 
the appropriate attribute objects.filter, the above should work exactly 
as you give it.

What is your actual problem? Are you asking for help in defining a 
queryset?



-- 
Steven



More information about the Python-list mailing list