How to “filter” by “exists” in Django?

I would like to filter a queryset by whether a certain subquery returns any results. In SQL this might look like this:

SELECT * FROM events e WHERE EXISTS
    (SELECT * FROM tags t WHERE t.event_id = e.id AND t.text IN ("abc", "def"))

In other words, retrieve all events which are tagged with one of the specified tags.

How might I express this using Django's QuerySet API on models Event and Tag?

5
задан Roman Starkov 15 October 2010 в 17:15
поделиться