DRF chain fields

Hello. In my project i use DRF, now i create CreateSerializer and I want to chain two fields in the serializer. how can this be done.

Yeah, I read the article https://simpleisbetterthancomplex.com/tutorial/2018/01/29/how-to-implement-dependent-or-chained-dropdown-list-with-django.html but, couldn’t solve problem with drf

class CreateDISerializer(serializers.ModelSerializer):
    s = serializers.PrimaryKeyRelatedField(
        queryset=DS.objects.all(),
    )

    d = serializers.PrimaryKeyRelatedField(
        queryset=D.objects.filter(s=s))

I believe that Serializer is not the right place to put a chained logic.

The chained fields can be implemented in forms, for example. You can use django-autocomplete to use chained fields in forms. It works with DRF.