def get_link_fields(self):
        """Construct dict of name:field for linkable fields."""
        if not hasattr(self, '_link_fields'):
            all_fields = self.get_all_fields()
            self._link_fields = {
                name: field for name, field in six.iteritems(all_fields)
                if isinstance(field, DynamicRelationField)
                and getattr(field, 'link', True)
                and not (
                    # Skip sideloaded fields
                    name in self.fields
                    and not field.serializer.id_only()
                ) and not (
                    # Skip included single relations
                    # TODO: Use links, when we can generate canonical URLs
                    name in self.fields
                    and not getattr(field.serializer, 'many', False)
                )
            }

        return self._link_fields
dataset/ETHPy150Open AltSchool/dynamic-rest/dynamic_rest/serializers.py/WithDynamicSerializerMixin.get_link_fields/original