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')

which would be equivalent to

    >>> Q(relfield__lookup=value)

and

    >>> qs.filter(relfield=Q(lookup=value))

which would be equivalent to

    >>> qs.filter(Q(lookup=value).push('relfield')).

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 [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?hl=en.

Reply via email to