def _get_reverse_relationships(opts):
    """
    Returns an `OrderedDict` of field names to `RelationInfo`.
    """
    # Note that we have a hack here to handle internal API differences for
    # this internal API across Django 1.7 -> Django 1.8.
    # See: https://code.djangoproject.com/ticket/24208

    reverse_relations = OrderedDict()
    for relation in get_all_related_objects(opts):
        accessor_name = relation.get_accessor_name()
        related = getattr(relation, 'related_model', relation.model)
        reverse_relations[accessor_name] = RelationInfo(
            model_field=None,
            related_model=related,
            to_many=relation.field.rel.multiple,
            to_field=_get_to_field(relation.field),
            has_through_model=False
        )

    # Deal with reverse many-to-many relationships.
    for relation in get_all_related_many_to_many_objects(opts):
        accessor_name = relation.get_accessor_name()
        related = getattr(relation, 'related_model', relation.model)
        reverse_relations[accessor_name] = RelationInfo(
            model_field=None,
            related_model=related,
            to_many=True,
            # manytomany do not have to_fields
            to_field=None,
            has_through_model=(
                (getattr(relation.field.rel, 'through', None) is not None) and
                not relation.field.rel.through._meta.auto_created
            )
        )

    return reverse_relations
Returns an `OrderedDict` of field names to `RelationInfo`.