title: Rest Framework Serializer Method
body: <p>I have the following Serializer using the <a href="http://www.django-rest-framework.org/api-guide/fields/#serializermethodfield" rel="noreferrer">Django REST Framework</a>. </p>
  
  <p>This is what I have so far...</p>
  
  <p><strong>serializer.py</strong></p>
  
  <pre><code>class ProductSerializer(serializers.ModelSerializer):
  
      score = serializers.SerializerMethodField('get_this_score')
  
      class Meta:
          model = Product
          fields = ('id', 'title', 'active', 'score')
  
      def get_this_score(self, obj):
  
          profile = Profile.objects.get(pk=19)
          score = [val for val in obj.attribute_answers.all() if val in profile.attribute_answers.all()]
          return (len(score))
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code> url(r'^products/(?P&lt;profile_id&gt;.+)/$', ProductListScore.as_view(), name='product-list-score'),
  </code></pre>
  
  <p>There are a few issues with this snippet of code.</p>
  
  <p>1) The pram pk=19 is hardcoded it should be <code>self.kwargs['profile_id'].</code> I have tried and tried, but I don't know how to pass kwarg into the method and cannot get profile_id to work. i.e. I cannot get  it from the url.</p>
  
  <p>2) Should any of this code be in models? I have tried adding to models, but again can pass the args.</p>
  
  <p><strong>models.py</strong>
   i.e. method class</p>
  
  <pre><code>     def get_score(self, profile):
  
          score = [val for val in self.attribute_answers.all() if val in 
  profile.attribute_answers.all()]
              return len(score)
  </code></pre>