def setup_joins(self, names, opts, alias, can_reuse=None, allow_many=True,
                    allow_explicit_fk=False, outer_if_first=False):
        joins = [alias]
        # First, generate the path for the names
        path, final_field, targets = self.names_to_path(
            names, opts, allow_many, allow_explicit_fk)
        # Then, add the path to the query's joins. Note that we can't trim
        # joins at this stage - we will need the information about join type
        # of the trimmed joins.
        for pos, join in enumerate(path):
            opts = join.to_opts
            if join.direct:
                nullable = self.is_nullable(join.join_field)
            else:
                nullable = True
            connection = alias, opts.db_table, join.join_field.get_joining_columns()
            reuse = can_reuse if join.m2m else None
            alias = self.join(
                connection, reuse=reuse, nullable=nullable, join_field=join.join_field,
                outer_if_first=outer_if_first)
            joins.append(alias)
        if hasattr(final_field, 'field'):
            final_field = final_field.field
        return final_field, targets, opts, joins, path
Compute the necessary table joins for the passage through the fields
dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/Django-1.6.10/django/db/models/sql/query.py/Query.setup_joins