Ticket #7907: 7907_2.diff

File 7907_2.diff, 1.9 KB (added by Shaun Cutts, 14 years ago)

update of the previous patch -- conforms to new sql compilation

  • django/db/models/sql/compiler.py

    diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
    index eaf2cd2..be878a4 100644
    a b class SQLCompiler(object):  
    449449                result.append('%s%s%s' % (connector, qn(name), alias_str))
    450450            first = False
    451451        for t in self.query.extra_tables:
     452            if isinstance(t, tuple):
     453                t, subselect = t
     454            else:
     455                subselect = None
    452456            alias, unused = self.query.table_alias(t)
    453457            # Only add the alias if it's not already present (the table_alias()
    454458            # calls increments the refcount, so an alias refcount of one means
    455459            # this is the only reference.
    456460            if alias not in self.query.alias_map or self.query.alias_refcount[alias] == 1:
    457461                connector = not first and ', ' or ''
    458                 result.append('%s%s' % (connector, qn(alias)))
     462                if subselect is None:
     463                    result.append('%s%s' % (connector, qn(alias)))
     464                else:
     465                    result.append('%s%s as %s' % (connector, subselect, qn(alias)))
    459466                first = False
    460467        return result, []
    461468
  • django/db/models/sql/query.py

    diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
    index 0913399..0234f4b 100644
    a b class Query(object):  
    16371637        if where or params:
    16381638            self.where.add(ExtraWhere(where, params), AND)
    16391639        if tables:
    1640             self.extra_tables += tuple(tables)
     1640            # allow tables to be dictionaries mapping names to subselects
     1641            if hasattr(tables, 'items'):
     1642                self.extra_tables += tuple(tables.items())
     1643            else:
     1644                self.extra_tables += tuple(tables)
    16411645        if order_by:
    16421646            self.extra_order_by = order_by
    16431647
Back to Top