django/django — pull request #2125 by akaariai (2013-12-28 15:05:33+00:00)
Title: Fixed #21696 -- filtering add_to_query() support

The ability to use add_to_query() objects was removed in Django 1.6.
It turned out that there were enough users for the private hook to
add it back.

The new API is a bit different. Where previously one would manipulate
directly query.where in add_to_query, now the add_to_query() must
return a node to add to query's where or having clauses. In addition
the return value should return joins to demote to INNER JOINs if that
is needed.

So, when previously you had this code:
def add_to_query(self, query, used_aliases):
...
self.where.add(something)

now you would do this intead:
def add_to_query(self, query, used_aliases):
...
return something, [] # change the empty list to join aliases
# used if you want inner joins for those.