Skip to content

Parsing Route Parameters #9040

@iamMHZ

Description

@iamMHZ

Suppose we have this urlpattern /<int:school_id>/courses and we wanna access school in the serializer ( I know that we can do self.context['view'].kwargs['school_id'])

But would it be possible to have it as a serializer field?
Something like this:

class CourseSerializer(serializers.Serializer):
    school = serializers.RouteParameter(name='school_id', queryset=School.objects.all())
    ....

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions