Skip to content

a request context in the output schema #1143

Answered by vitalik
jankrnavek asked this question in Q&A
Discussion options

You must be logged in to vote

@jankrnavek

sure - https://django-ninja.dev/guides/response/?h=resolve_#accessing-extra-context

class Some(Schema):
    ...
    my_fields: list[User] = []

    @staticmethod
    def resolve_my_fields(obj, context):
        request = context["request"]
        user = request.user
        return user.friends.all()

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jankrnavek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants