code: def build_relational_field(self, field_name, relation_info):
          
          field_class = self.serializer_related_field
          field_kwargs = get_relation_kwargs(field_name, relation_info)
  
          to_field = field_kwargs.pop('to_field', None)
          if to_field and not relation_info.related_model._meta.get_field(to_field).primary_key:
              field_kwargs['slug_field'] = to_field
              field_class = self.serializer_related_to_field
  
          # `view_name` is only valid for hyperlinked relationships.
          if not issubclass(field_class, HyperlinkedRelatedField):
              field_kwargs.pop('view_name', None)
  
          return field_class, field_kwargs
docs: Create fields for forward and reverse relationships.