Ticket #7907: 7907.patch

File 7907.patch, 1.7 KB (added by Samuel Cormier-Iijima, 16 years ago)
  • django/db/models/sql/query.py

     
    541541                result.append('%s%s%s' % (connector, qn(name), alias_str))
    542542            first = False
    543543        for t in self.extra_tables:
     544            if isinstance(t, tuple):
     545                t, subselect = t
     546            else:
     547                subselect = None
    544548            alias, unused = self.table_alias(t)
    545549            # Only add the alias if it's not already present (the table_alias()
    546550            # calls increments the refcount, so an alias refcount of one means
    547551            # this is the only reference.
    548552            if alias not in self.alias_map or self.alias_refcount[alias] == 1:
    549553                connector = not first and ', ' or ''
    550                 result.append('%s%s' % (connector, qn(alias)))
     554                if subselect is None:
     555                    result.append('%s%s' % (connector, qn(alias)))
     556                else:
     557                    result.append('%s%s as %s' % (connector, subselect, qn(alias)))
    551558                first = False
    552559        return result, []
    553560
     
    15601567        if params:
    15611568            self.extra_params += tuple(params)
    15621569        if tables:
    1563             self.extra_tables += tuple(tables)
     1570            # allow tables to be dictionaries mapping names to subselects
     1571            if hasattr(tables, 'items'):
     1572                self.extra_tables += tuple(tables.items())
     1573            else:
     1574                self.extra_tables += tuple(tables)
    15641575        if order_by:
    15651576            self.extra_order_by = order_by
    15661577
Back to Top