is there any way to make choices dynamically depend on current user something like that:
class RideSerializer(serializers.ModelSerializer):
provider_username = serializers.ChoiceField(choices=request.user.providers)
is there any way to make choices dynamically depend on current user something like that:
class RideSerializer(serializers.ModelSerializer):
provider_username = serializers.ChoiceField(choices=request.user.providers)
Copyright © 2021 Jogjafile Inc.
You can set the choices during in the constructor. The following code show the idea. You can pass the request via context https://www.django-rest-framework.org/api-guide/serializers/#including-extra-context