我有django rest framework api应用程序并为它生成文档。我使用视图集api视图,我有自定义方法。在网址中我使用路由器。对于生成文档,我使用DRF文档。
我的观点:
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方法的自定义注释并显示不同的字段,因为我使用此方法的其他序列化程序。我怎么能这样做?