You can always use itertools.chain() if you want to do it in memory. Instead of doing it in memory as you've suggested, perhaps you need to index the account's PK so when your Items object manager queries for them, it can be quick.
import itertools list1 = [1,2,3,4] list2 = ['a','b','c','d'] combined_list = itertools.chain(list1, list2) On Tuesday, November 6, 2012 2:56:18 AM UTC-7, Neil Pritchard wrote: > > Hi, > > I have an application that needs to do a fairly big search across a large > number of records that goes something like... > > filterList = accounts.objects.filter(name="foo", company="bar", blah blah > blah..) > > itemsList = items.objects.filter(account__in=accountList, > status="delivered", andSo="on"....) > > > > The problem that I would like to overcome is that the > 'account__in=accountList' creates some very inefficient SQL and slow's this > query down a lot. > > What I thought of doing instead was: > > filterList = accounts.objects.filter(name="foo", company="bar", blah blah > blah..) > > for account in filterList: > > itemsList = items.objects.filter(account=account, status="delivered", > andSo="on"....) > > # I know it's not possible to extend a django queryset, I'm looking > for an equivalent > wholeItemsList.extend(itemsList) > > > Now I know the .extend method won't work on a django queryset, and I > realise that it's possible to convert the queryset to a list and than > extend them but that would use a horrible ammount of memory to duplicate > the queryset in this instance and wouldn't give me much of a time advantage. > > What I would like to do is to add each of the querysets, searching for > them without the '__in' filter saves a lot on sql, but then I don't want to > loose the efficiency that would gain by adding another latency. > > Any Ideas would be greatly appreciated.... > > > Many thanks, > > Neil > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/-vBMH9yHQtYJ. To post to this group, send email to django-users@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.