> So I suppose my question is this - are there any operations that return a
queryset that couldn't be captured in a Q object?
Annotations are a good example of operations that cannot be expressed in a
Q object.
On the ticket I suggested relying on the "sticky filter" feature of the ORM
to implement a combinable filter spec.
Sticky filters allow chained filter() calls to reuse aliases, making
filter(lookup=1).filter(lookup=2) equivalent to filter(lookup=1, lookup=2)
while the queryset is marked a "sticky"
They are only used internally by the ORM but I remember a ticket where
Anssii mentioned we wight want to expose the feature through a more
adequate API.
e.g.
with queryset.reuse_aliases() as qs:
qs = qs.filter(lookup=1).filter(lookup=2)
assert qs == queryset.filter(lookup=1, lookup=2)
This would make it easy to implement a "combinable" filter spec and allow
users to solve the issues that have surfaced recently about how the admin
does search and filtering through multiple joins. For example, one could
override get_search_results() to reuse aliases easily by relying on this
method and implementing the "combinable" filter spec class would only be a
matter of creating a composite filter spec that reuse aliases in queryset()
before delegating to each of its nested filters.
Simon
Le vendredi 7 octobre 2016 05:52:02 UTC-4, Andy Baker a écrit :
>
> Actually - my recollection was faulty. As the queryset method always has
> to return a queryset (dur) I am not sure that I'm actually doing anything
> that couldn't be expressed as a Q object. I'm just doing some funky stuff
> to get my queryset in shape.
>
> So I suppose my question is this - are there any operations that return a
> queryset that couldn't be captured in a Q object?
>
--
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 [email protected].
To post to this group, send email to [email protected].
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/87229a92-860d-408c-91a5-81182cb8fb81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.