Django REST Framework - pass extra parameter to actions

后端 未结 3 537
梦谈多话
梦谈多话 2021-02-02 09:54

I\'m using Django 2.0 and Django REST Framework

I have created an action method to delete particular object from database

conta

3条回答
  •  广开言路
    2021-02-02 10:18

    Solved the problem using drf-nested-routers

    For those who need it, install the plugin and configure urls.py

    from rest_framework_nested import routers
    
    router = routers.SimpleRouter()
    router.register(r'contacts', ContactViewSet, 'contacts')
    contact_router = routers.NestedSimpleRouter(router, r'contacts', lookup='contact')
    contact_router.register(r'phone_number', ContactPhoneNumberViewSet, base_name='contact-phone-numbers')
    
    api_urlpatterns = [
        path('', include(router.urls)),
        path('', include(contact_router.urls))
    ]
    

提交回复
热议问题