title: AssertionError: `HyperlinkedIdentityField` requires the request in the serializer context
body: <p>I want to create a <code>many-to-many</code> relationship where one person can be in many clubs and one club can have many persons. I added the <code>models.py</code> and <code>serializers.py</code> for the following logic but when I try to serialize it in the command prompt, I get the following error - What am I doing wrong here? I don't even have a <code>HyperlinkedIdentityField</code></p>
  <pre><code>Traceback (most recent call last):
  File &quot;&lt;console&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;C:\Users\user\corr\lib\site-packages\rest_framework\serializers.py&quot;, line 503, in data
  ret = super(Serializer, self).data
  File &quot;C:\Users\user\corr\lib\site-packages\rest_framework\serializers.py&quot;, line 239, in data
  self._data = self.to_representation(self.instance)
  File &quot;C:\Users\user\corr\lib\site-packages\rest_framework\serializers.py&quot;, line 472, in to_representation
  ret[field.field_name] = field.to_representation(attribute)
  File &quot;C:\Users\user\corr\lib\site-packages\rest_framework\relations.py&quot;, line 320, in to_representation&quot;the serializer.&quot; % self.__class__.__name__
  AssertionError: `HyperlinkedIdentityField` requires the request in the serializer context. Add `context={'request': request}` when instantiating the serializer.
  </code></pre>
  <p><code>models.py</code></p>
  <pre><code>class Club(models.Model):
      club_name = models.CharField(default='',blank=False,max_length=100)
  
  class Person(models.Model):
      person_name = models.CharField(default='',blank=False,max_length=200)
      clubs = models.ManyToManyField(Club)
  </code></pre>
  <p><code>serializers.py</code></p>
  <pre><code>class ClubSerializer(serializers.ModelSerializer):
      class Meta:
          model = Club
          fields = ('url','id','club_name','person')
  
  class PersonSerializer(serializers.ModelSerializer):
      clubs = ClubSerializer()
      class Meta:
          model = Person
          fields = ('url','id','person_name','clubs')
  </code></pre>
  <p><code>views.py</code></p>
  <pre><code>class ClubDetail(generics.ListCreateAPIView):
  serializer_class = ClubSerializer
  
  def get_queryset(self):
       club = Clubs.objects.get(pk=self.kwargs.get('pk',None))
       persons = Person.objects.filter(club=club)
       return persons
  
  class ClubList(generics.ListCreateAPIView):
      queryset = Club.objects.all()
      serializer_class = ClubSerializer
  
  
  class PersonDetail(generics.RetrieveUpdateDestroyAPIView):
      serializer_class = PersonSerializer
  
  
  def get_object(self):
      person_id = self.kwargs.get('pk',None)
      return Person.objects.get(pk=person_id) 
  </code></pre>
  <p>Inspecting the created serializer gives me this -</p>
  <pre><code>PersonSerializer(&lt;Person: fd&gt;):
  url = HyperlinkedIdentityField(view_name='person-detail')
  id = IntegerField(label='ID', read_only=True)
  person_name = CharField(max_length=200, required=False)
  clubs = ClubSerializer():
      url = HyperlinkedIdentityField(view_name='club-detail')
      id = IntegerField(label='ID', read_only=True)
      club_name = CharField(max_length=100, required=False)
  </code></pre>
  <p>but <code>serializer.data</code> gives me the error</p>
  <blockquote>
  <p>Edit</p>
  </blockquote>
  <p>I realized the error could be because of <code>url</code> patterns, so I added the following url patterns but I still get the error -</p>
  <pre><code>urlpatterns = format_suffix_patterns([
  url(r'^$', views.api_root),
  url(r'^clubs/$',
      views.ClubList.as_view(),
      name='club-list'),
   url(r'^clubs/(?P&lt;pk&gt;[0-9]+)/persons/$',
      views.ClubDetail.as_view(),
      name='club-detail'),
  url(r'^person/(?P&lt;pk&gt;[0-9]+)/$',
      views.PersonDetail.as_view(),
      name='person-detail'),
  ])
  </code></pre>