title: DRF - Base Viewset for query param validation
body: <p>I am using Django 1.9 and Django Rest Framework 3.3</p>
  
  <p>I'm creating three new endpoints that are similar but still different enough that I want them to be their own viewsets to avoid messy code. They are not backed by a model so I am extending <code>ViewSet</code> directly. One similarity between all three endpoints is they require the same two query parameters. So I find I am doing this:</p>
  
  <pre><code>class MyFirstViewset(viewsets.ViewSet):
  
      def list(self, request):
          some_param = request.query_params.get('someparam')
          if not some_param:
              return Response('someparam query parameter is required', status.HTTP_400_BAD_REQUEST)
          some_other_param = request.query_params.get('someotherparam')
          if not some_other_param:
                return Response('someotherparam query parameter is required', status.HTTP_400_BAD_REQUEST)
  
  
  class MySecondViewset(viewsets.ViewSet):
  
      def list(self, request):
          some_param = request.query_params.get('someparam')
          if not some_param:
              return Response('someparam query parameter is required', status.HTTP_400_BAD_REQUEST)
          some_other_param = request.query_params.get('someotherparam')
          if not some_other_param:
                return Response('someotherparam query parameter is required', status.HTTP_400_BAD_REQUEST)
  </code></pre>
  
  <p>As you can see... it's not very DRY. An obvious solution would be inheritance with a base viewset doing the similar parts of validation, the problem is I'm not sure what the best practice is for doing something like this with DRF. Would I want to make a protected access validation function and call that? But if all I was doing was checking a dict for keys it wouldn't even have to be in a ViewSet right? Just having the last class do the validation in <code>list()</code> then calling that in all the child viewsets also seems odd to me since then I am using <code>list()</code> to validate and not actually return anything in the base class.</p>
  
  <p>Could anyone tell me what a good approach to this would be? What's best practice for cases like this? I Googled around but couldn't find anything. Any advice would be appreciated. Thanks!</p>