@@ -666,8 +666,13 @@ def _map_serializer_field(self, field, direction, bypass_extensions=False):
666666 # read_only fields do not have a Manager by design. go around and get field
667667 # from parent. also avoid calling Manager. __bool__ as it might be customized
668668 # to hit the database.
669- if getattr (field , 'queryset' , None ) is not None and not is_slug :
670- model_field = field .queryset .model ._meta .pk
669+ if getattr (field , 'queryset' , None ) is not None :
670+ if is_slug :
671+ model = field .queryset .model
672+ source = [field .slug_field ]
673+ model_field = follow_field_source (model , source , default = models .TextField ())
674+ else :
675+ model_field = field .queryset .model ._meta .pk
671676 else :
672677 if isinstance (field .parent , serializers .ManyRelatedField ):
673678 model = field .parent .parent .Meta .model
@@ -689,10 +694,8 @@ def _map_serializer_field(self, field, direction, bypass_extensions=False):
689694
690695 # estimates the relating model field and jumps to its target model PK field.
691696 # also differentiate as source can be direct (pk) or relation field (model).
692- model_field = follow_field_source (model , source )
693- if callable (model_field ):
694- # follow_field_source bailed with a warning. be graceful and default to str.
695- model_field = models .TextField ()
697+ # be graceful and default to string.
698+ model_field = follow_field_source (model , source , default = models .TextField ())
696699
697700 # primary keys are usually non-editable (readOnly=True) and map_model_field correctly
698701 # signals that attribute. however this does not apply in the context of relations.
0 commit comments