Django-ninja如何在schema中使用request.user

@http_get('like', response=BookSchema, url_name='like')
def like(self, request,id):
        book= Book.objects.filter(id=id)
        book._user = request.user   //指定user对象
        return book


class BookSchema(ModelSchema):
    books: list

    class Config:
        model = Book
        model_fields =   '__all__'

    @staticmethod
    def resolve_books(obj):
       obj._user   //此处可以使用request.user
        return obj.books

你可能感兴趣的:(django,python,后端)