Luke Plant wrote: > On Friday 05 May 2006 12:47, Michael Radziej wrote: >> Hi, >> >> what about providing class functions QuerySet.union(cls, qset_list), >> QuerySet.intersection(cls, qset_list), both returning cls, such as: >> >> def union(cls, qset_list): >> """Returns the union of a list of QuerySets, a QuerySet.""" >> return reduce(cls.__or__, qset_list) >> >> union = classmethod(union) >> > Yes, I agree we should complete the parallel with Python sets. > > With Python built-in sets, 'some_set.union(iterable)' is exactly the > same as 'some_set | set(iterable)' (and similarly with 'intersection' > and '&') so you have this identity: > > some_set.union(other_set) == some_set | other_set > > Your example code has different semantics: > > some_qset.union([other_qset]) == some_qset | other_qset > ...
Sorry for the long delay, your posting confused me about what I want ;-) My original intentions are completely different from Luke's. I really need a function that builds the union over any list (or any iterator). Perhaps an example helps: union([aModelInstance.related_set for aModelInstance in someFunction()]) where someFunction is more or a less a kind of business rule that defines a data set. Luke's idea is really imlemented very easily, since QuerySet.union is the same as QuerySet.__or__. I really don't care much whether the underlying database engine does a OR or a UNION. Am I too naive here? Now, it's probably a bad idea to do it diffent from sets. Is then anyone still interested in my original proposal (like above) under a different name, or was it all just a misunderstanding? Michael --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---
