Is this going to be different from the pipe ( | ) and and ( & ) operators on querysets? If I'm not wrong those can already result in a union query (but not necessary, sometimes it just returns a query with an or/and condition)
El viernes, 23 de diciembre de 2016, 11:12:40 (UTC-3), Florian Apolloner escribió: > > Hi, > > I have a currently WIP PR at https://github.com/django/django/pull/7727 > > The 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 > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d38358ca-c97f-4bb0-a390-e38f3b4b8f6c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.