我有 django rest framework api 应用程序并为其生成文档。我使用带有视图集的 api 视图,并且我有自定义方法。在网址中,我使用路由器。对于生成文档,我使用 DRF Docs。
我的观点:
class UserViewSet(viewsets.ModelViewSet):
"""View for user object.
"""
...
@detail_route(methods=["post"])
def set_password(self, request, pk=None):
"""View to set new password
"""
...
网址:
from django.conf.urls import url, include
from rest_framework.routers import DefaultRouter
from accounts.views import UserViewSet
__all__ = ["accounts_urlpatterns"]
accounts_router = DefaultRouter()
accounts_router.register(r'users', UserViewSet)
accounts_urlpatterns = [
url(r'^accounts/', include(accounts_router.urls))
]
我想要 set_password 方法的自定义注释并显示不同的字段,因为我将此方法用于其他序列化程序。我怎样才能做到这一点?