Hi,
I have a currently WIP PR at
https://github.com/django/django/pull/7727The usage is currently something like this:
qs1 = User.objects.all().values('username')
qs2 = Group.objects.all().values('name')
results = qs1.union(qs).distinct().order_by('name')[:10]
(order_by does not work though yet)
So far I have a few questions:
* Should .union/.intersect etc return a new type of queryset or stay with the base QuerySet class (probably less code duplication)
* We currently have a few methods which check can_filter and error out accordingly (ie you cannot filter after slicing), but as the error message in
https://github.com/django/django/blob/master/django/db/models/query.py#L579 shows, this strongly relies on knowledge of the implementation of the filter. For combined querysets I basically need to limit everything aside from order by and limit/offset. Would a method like this make some sense (on the Query class):
def is_allowed(self, action):
if self.combinatorial and action not in ('set_operation', 'order_by', 'slicing'):
raise SomeError('Cannot use this method on an combinatorial queryset')
elif action == 'filter' and
(self.low_mark or self.high_mark):
raise SomeError('Cannot filter after slicing')
* set_operator in base.py feels a bit weird (
https://github.com/django/django/pull/7727/files#diff-53fcf3ac0535307033e0cfabb85c5301) -- any better options?
* How can I change the generated order_by clause to reference the columns "unqualified" (ie without table name), can I somehow just realias every column?
Cheers,
Florian