On Fri, Sep 30, 2011 at 5:37 PM, Johannes Dollinger
<emulb...@googlemail.com> wrote:
> The aim of this proposal is to reuse Q objects for models that are related 
> through FK or M2M fields.
> A simplified example would be a Q object like
>
>    >>> is_blue = Q(blue=True)
>    >>> Thing.objects.filter(is_blue)
>
> that should be reused to filter the owners of things:
>
>    >>> User.objects.filter(things__blue=True).
>
> Currently, the only way to reuse the Q object would be subquery:
>
>    >>> User.objects.filter(things__in=Thing.objects.filter(is_blue)).
>
> I therefore propose the following API:
>
>    >>> Q(lookup=value).push('relfield')

I don't like this.

> which would be equivalent to
>
>    >>> Q(relfield__lookup=value)
>
> and
>
>    >>> qs.filter(relfield=Q(lookup=value))

I do like this

> which would be equivalent to
>
>    >>> qs.filter(Q(lookup=value).push('relfield')).

Again, not this.

Are you only proposal the push method as an implementation detail? If
so, don't let it be part of the API proposal itself.

> We then could write
>
>    >>> User.objects.filter(things=is_blue)
>
> which is shorter and produces more natural SQL than the subquery solution.
>
> Thoughs? Suggestions?
>
> __
> Johannes
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django developers" group.
> To post to this group, send email to django-developers@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-developers+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-developers?hl=en.
>
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to