QLeftOuterJoins

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from django.db.models.query import Q, QAnd, QOr

class QLeftOuterJoins(Q):
    "Replaces all INNER JOINs with LEFT OUTER JOINs inside"
    def __init__(self, q):
        self.q = q

    def __and__(self, other):
        return QAnd(self, other)

    def __or__(self, other):
        return QOr(self, other)

    def get_sql(self, opts):
        joins, where, params = self.q.get_sql(opts)
        for join_name, join in joins.iteritems():
            joins[join_name] = (join[0], "LEFT OUTER JOIN", join[2])
        return joins, where, params

More like this

  1. Left Outer join Q object by karsu 4 years, 11 months ago
  2. Self Join Possible? by slacy 1 year, 6 months ago
  3. make a combined set of db.Q objects out of a list of dicts and an operator by jdunck 3 months, 4 weeks ago
  4. Q marshaller by Spike^ekipS 4 years, 2 months ago
  5. CategoriesField by fongandrew 2 years, 9 months ago

Comments

(Forgotten your password?)