On Monday 05 June 2006 14:57, benj wrote: > def index(request): > titles = list(Alias.objects.all()) + list( Song.objects.all()) > titles.sort(lambda x, y: cmp(x.title, y.title) > return render_to_response('songs/index.html', {'titles': titles}) > > > This gives me lists of objects with the correct attributes and > methods which is great, and when I need to filter the results (for > example, for category views) I can easily do that by replacing .all() > with .filter() or whatever else. The problem with this solution is > that I need to pull the entire set of results into a list, and (if > the site catches on), that's bad memory use and potentially slow. I > wish it were possible to create an iterable object like a queryset > that could be assigned two models to do this more efficiently. If > anyone has advice about any more efficient way to get this done, I'd > appreciate it.
Django's ORM can only do what is possible in SQL -- unless you can think of SQL that will do this, it can't be done. One possible method is to create a VIEW in your db that does a UNION of columns from different tables. If you create an index on that view, you may be able to do an ORDER BY efficiently over the relevant column. I'm not sure though. Obviously it depends on your db supported indexed views. Luke -- "Whoever calls on the name of the LORD will be saved." (Romans 10:13) Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---