'A wrapper around connection.ops.quote_name that doesn\'t quote aliases
for table names. This avoids problems with some SQL dialects that treat
quoted strings specially (e.g. PostgreSQL).'

def quote_name_unless_alias(self, name):

    if (name in self.quote_cache):
        return self.quote_cache[name]
    if (((name in self.query.alias_map) and (name not in self.query.table_map)) or (name in self.query.extra_select)):
        self.quote_cache[name] = name
        return name
    r = self.connection.ops.quote_name(name)
    self.quote_cache[name] = r
    return r
