django-rest custom url in a ModelViewSet

后端 未结 1 959
陌清茗
陌清茗 2021-01-05 05:57

I\'m having an issue adding a custom URL to a ModelViewSet in django-rest-framework. Here\'s an example of my main urls.py

router = routers.DefaultRouter()
r         


        
相关标签:
1条回答
  • 2021-01-05 06:43

    Pull the list method out as a separate view:

    post_list = PostViewSet.as_view({'get': 'list'})
    

    Then map this to your date-based lookup URL as you usually would, setting parameters for year, month and day.

    In get_queryset you can check if these kwargs are set and, if so, filter the queryset.

    0 讨论(0)
提交回复
热议问题