#13489: Arbitrary Q filter on related model fields ---------------------------+------------------------------------------------ Reporter: jnothman | Owner: nobody Status: new | Milestone: Component: Uncategorized | Version: 1.1 Keywords: | Stage: Unreviewed Has_patch: 0 | ---------------------------+------------------------------------------------ Given a model with a foreign key, e.g. the classic Entry / Blog example, we may want to select/aggregate over entries contained in blogs with certain features. We can e.g. perform a filter over the joined relation:
{{{ Entry.objects.filter(blog__tagline__contains="foobar") }}} As far as I know, we cannot define a Q instance defined to filter Blog (which may be pre-defined for other purposes) to perform the same filter over a join: The closest we can get (in 1.1) is: {{{ q = Q(tagline__contains="foobar") Entry.objects.filter(blog_in=q) }}} which performs a sub-select query, with the same results, but different efficiency, and different fields available for output. I propose one of two syntax options: {{{ Entry.objects.filter(blog_has=q) }}} or: {{{ Entry.objects.filter(q.apply_to_field('blog')) }}} -- Ticket URL: <http://code.djangoproject.com/ticket/13489> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.