[Answered ]-DRF: Need Guidance to perform a task

1👍

I hope this should work,

class BookingSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Booking
        fields = '__all__'
        read_only_fields = ("user", "advisor")

    def create(self, validated_data):
        view_kwargs = self.context["view"].kwargs
        booking = models.Booking.objects.create(
            user_id=view_kwargs["user_id"],
            advisor_id=view_kwargs["advisor_id"],
            time=validated_data['time']
        )
        return booking
👤JPG

Leave a comment