title: Overriding Django REST ViewSet with custom post method and model
body: <p>I have a a <code>ModelViewSet</code> in Django's REST Framework that gives me the ability to do a POST and GET through the following address:</p>
  
  <p><code>api/v1/users</code></p>
  
  <p>These Users have a a reverse relation to a Comments table and I'd like to be able to access these Comments through the URL:</p>
  
  <p><code>api/v1/users/&lt;username&gt;/comments</code></p>
  
  <p>I was able to do this by setting up a custom <code>@detail_route</code> by overriding the <code>queryset</code> and and <code>serializer_class</code> but it only works for GET requests. If I attempt to POST a new comment through the REST Framework's admin section, I receive an error notice stating "'ListSerializer' object is not iterable"</p>
  
  <p>Here's my code:</p>
  
  <pre><code>class UserViewSet(viewsets.ModelViewSet):
      queryset         = User.objects.all()
      serializer_class = UserFlat
      lookup_field     = 'username'
  
  
      @detail_route(methods=['post','get'])
      def comment(self, request, **kwargs):
  
          user = self.get_object()
  
          self.queryset         = Comment.objects.filter(recipient=user.id)
          self.serializer_class = CommentFlat
  
          serializer = CommentFlat(instance=self.queryset, many=True)
  
          return Response(serializer.data)
  </code></pre>
  
  <p>The new comment should take the following parameters:</p>
  
  <p>comment.author, comment.message, comment.recipient</p>
  
  <p>I can enter all those fields in the admin panel and attempt to create a post request but it fails. Ideally, I should only have to fill out comment.message and comment.author and the comment.recipient field should be autopopulated with user.id which is obtained in the url <code>api/v1/users/&lt;username&gt;/comments</code></p>
  
  <p>Does anyone know why my post request isn't completing and how I can autofill that one field?</p>