def _add_request_prefetches(
        self,
        prefetches,
        requirements,
        model,
        fields,
        filters
    ):
        for name, field in six.iteritems(fields):
            original_field = field
            if isinstance(field, DynamicRelationField):
                field = field.serializer
            if isinstance(field, serializers.ListSerializer):
                field = field.child
            if not isinstance(field, serializers.ModelSerializer):
                continue

            source = field.source or name
            if '.' in source:
                raise ValidationError(
                    'nested relationship values '
                    'are not supported'
                )

            if source in prefetches:
                # ignore duplicated sources
                continue

            is_remote = is_field_remote(model, source)
            is_id_only = getattr(field, 'id_only', lambda: False)()
            if is_id_only and not is_remote:
                continue

            prefetch_queryset = self._build_prefetch_queryset(
                name,
                original_field,
                field,
                filters,
                requirements
            )

            # Note: There can only be one prefetch per source, even
            #       though there can be multiple fields pointing to
            #       the same source. This could break in some cases,
            #       but is mostly an issue on writes when we use all
            #       fields by default.
            prefetches[source] = Prefetch(
                source,
                queryset=prefetch_queryset
            )
Add external (requested) prefetches to a prefetch dictionary.
dataset/ETHPy150Open AltSchool/dynamic-rest/dynamic_rest/filters.py/DynamicFilterBackend._add_request_prefetches