On Dec 11, 2:22 pm, mbdtsmh <martin.harri...@astrazeneca.com> wrote: > Hi all - can someone put me out of my misery on this one please? > > I have a piece of code that uses the request.GET keys in the url to > produce the following in my views.py > > objects = Issue.objects.all() > objects = objects.filter > (designset__project__RA__RA=request.GET.__getitem__('RA')).distinct() > objects = objects.filter > (designset__project__phase__phase=request.GET.__getitem__ > ('phase')).distinct() > > the time spent in the code using this approach is ~14 seconds > > However, if I use the combined filter... > > objects = Issue.objects.all() > objects = objects.filter > (designset__project__RA__RA=request.GET.__getitem__ > ('RA'),designset__project__phase__phase=request.GET.__getitem__ > ('phase')).distinct() > > then the time spent reduces to ~2 seconds > > this is a significant difference so I'd like to understand why this > occurs as I thought you could combine filters and not hit the > database? > > Any words of wisdom would be much appreciated on this. > > Regards, > > Martin
Firstly, please please do not use __getitem__. That's an internal method. Use request.GET.get(). Secondly, are you sure that the two queries above result in the same SQL? Have you looked at the queries that are actually performed against the database? from django.db import connection print connection.queries -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.