title: Django REST Framework -- destroy method won't take on URL params?
body: <p>I am designing an API endpoint using Django REST Framework, and would like for it to accept GET and POST methods at the following endpoint:</p>
  
  <pre><code>companies/&lt;company_pk&gt;/membership
  </code></pre>
  
  <p>as well as DELETE methods at the following endpoint:</p>
  
  <pre><code>companies/&lt;company_pk&gt;/membership/&lt;membership_pk&gt;
  </code></pre>
  
  <p>There are two relevant models: <code>Company</code> and <code>CompanyMembership</code>. Each user can be a member of one or more companies,which is represented by an instance of <code>CompanyMembership</code>, which linked by a FK to <code>Company</code>.</p>
  
  <p>I've created the appropriate GET and POST requests, but am having trouble with the DELETE requests -- it seems that the <code>destroy</code> method within my view is missing the <code>membership_pk</code> parameter, whether or not I define it within my URLs. How can I have my view accept DELETE requests which delete instances of <code>CompanyMembership</code>, which are identified by the <code>membership_pk</code> given in the URL?</p>
  
  <pre><code>urls.py
  
  ...
      url(r'^companies/(?P&lt;company_pk&gt;[0-9]+)/membership', include(company_urls.company_membership_router.urls,
          namespace='company_memberships')),
  ...
  
  views.py
  
  
  class CompanyMembershipViewSet(viewsets.ModelViewSet):
      """
      A ViewSet for creating, retrieving, and deleting CompanyMemberships.
      """
      queryset = CompanyMembership.objects.all()
      serializer_class = CompanyMembershipSerializer
      lookup_url_kwarg = 'company_pk'
  
      def get_queryset(self):
          uid = self.kwargs.get(self.lookup_url_kwarg)
          memberships = CompanyMembership.objects.filter(company_id=uid)
          return memberships
  
      def create(self, request, company_pk):
          """
          Custom create method since company_pk does not have to be sent
          explicitly within request.data
  
          Returns: instance of rest_framework Response.
          """
          EXISTING_USER_ERROR = {'non_field_errors':
              ['The fields user, company must make a unique set.']
          }
          data = {
              'user': request.data['user'],
              'company': company_pk
          }
          serializer = CompanyMembershipSerializer(data=data)
          if serializer.is_valid():
              serializer.save()
              return Response(serializer.data, status=status.HTTP_201_CREATED)
          if serializer.errors == EXISTING_USER_ERROR:
              return Response(serializer.errors, status=settings.ADDITIONAL_HTTP_STATUS_CODES['422_UNPROCESSABLE_ENTITY'])
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  
      def destroy(self, request, **kwargs):
          company_membership = self.get_object(pk=membership_pk)
          company_membership.delete()
          return Response(status=status.HTTP_204_NO_CONTENT)
  
  
  routers.py
      from rest_framework import routers
  
      from .views import CompanyViewSet, CompanyMembershipViewSet
  
  
      company_router = routers.DefaultRouter()
      company_membership_router = routers.DefaultRouter()
  
      company_router.register(r'^', CompanyViewSet)
      company_membership_router.register(r'^', CompanyMembershipViewSet)
  </code></pre>