title: DRF Could not resolve URL for hyperlinked relationship using view name on PrimaryKeyRelatedField
body: <p>I have a frustrating problem with POST requests on a DRF serializer - DRF is, for some reason, going to an incorrect view name, and <code>view_name</code> is not a settable property on <code>PrimaryKeyRelated Field</code>.</p>
  <p>Models:</p>
  <pre class="lang-py prettyprint-override"><code># (the class with the issue)
  class Section(models.Model):
      teacher = models.ManyToManyField(Teacher)
  
  # (a class that works, using the same pattern)
  class Assessment(models.Model):
      standards = models.ManyToManyField(Standard)
  </code></pre>
  <p>Serializers:</p>
  <pre class="lang-py prettyprint-override"><code># (doesn't work)
  class SectionInfoSerializer(serializers.HyperlinkedModelSerializer):
      url = serializers.HyperlinkedIdentityField(view_name=&quot;gbook:section-detail&quot;)
      teacher = serializers.PrimaryKeyRelatedField(many=True, read_only=True),
      teachers_id = serializers.PrimaryKeyRelatedField(write_only=True, queryset=Teacher.objects.all(), many=True, source='teacher', allow_empty=False)
  
      class Meta:
          model = Section
          fields = '__all__'
          read_only_fields = ['sendEmails', 'teacher', 'course']
  
  # (works)
  class AssessmentSerializer(serializers.HyperlinkedModelSerializer):
      pk = serializers.PrimaryKeyRelatedField(read_only=True)
      url = serializers.HyperlinkedIdentityField(view_name=&quot;appname:assessments-detail&quot;)
      standards = serializers.PrimaryKeyRelatedField(read_only=True, many=True)
      standards_id = serializers.PrimaryKeyRelatedField(queryset=Standard.objects.all(), source='standards', write_only=True, many=True, allow_empty=False)
  
      class Meta:
          model = Assessment
          fields = '__all__'
  
  </code></pre>
  <p>urls:</p>
  <pre><code>router.register(r'teachers', teacher_views.TeacherViewSet, basename='teacher')
  router.register(r'sections', course_views.SectionViewSet)
  router.register(r'standards', gbook.views.standard_views.StandardViewSet, basename='standards')
  router.register(r'assessments', AssessmentViewSet, basename='assessments')
  </code></pre>
  <p>I'm using the <code>_id</code> fields during POST and PUT to send the id's of the related obejcts, then serializing them. This worked great with <code>AssessmentSerializer</code> (and several others), but is failing for a reason that I can't figure out. Certainly, the appname is missing from the view returned in the error, but I don't know why that's happening, and why it didn't happen before.</p>
  <p>Stack trace:</p>
  <pre><code>Internal Server Error: /appname/sections/
  Traceback (most recent call last):
    File &quot;/venv2/lib/python3.8/site-packages/rest_framework/relations.py&quot;, line 393, in to_representation
      url = self.get_url(value, self.view_name, request, format)
    File &quot;/venv2/lib/python3.8/site-packages/rest_framework/relations.py&quot;, line 331, in get_url
      return self.reverse(view_name, kwargs=kwargs, request=request, format=format)
    File &quot;/venv2/lib/python3.8/site-packages/rest_framework/reverse.py&quot;, line 47, in reverse
      url = _reverse(viewname, args, kwargs, request, format, **extra)
    File &quot;/venv2/lib/python3.8/site-packages/rest_framework/reverse.py&quot;, line 60, in _reverse
      url = django_reverse(viewname, args=args, kwargs=kwargs, **extra)
    File &quot;/venv2/lib/python3.8/site-packages/django/urls/base.py&quot;, line 87, in reverse
      return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
    File &quot;/venv2/lib/python3.8/site-packages/django/urls/resolvers.py&quot;, line 685, in _reverse_with_prefix
      raise NoReverseMatch(msg)
  django.urls.exceptions.NoReverseMatch: Reverse for 'teacher-detail' not found. 'teacher-detail' is not a valid view function or pattern name.
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;/lib/python3.8/site-packages/django/core/handlers/exception.py&quot;, line 47, in inner
      response = get_response(request)
    File &quot;/lib/python3.8/site-packages/django/core/handlers/base.py&quot;, line 179, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File &quot;/lib/python3.8/site-packages/django/views/decorators/csrf.py&quot;, line 54, in wrapped_view
      return view_func(*args, **kwargs)
    File &quot;/lib/python3.8/site-packages/rest_framework/viewsets.py&quot;, line 114, in view
      return self.dispatch(request, *args, **kwargs)
    File &quot;/lib/python3.8/site-packages/rest_framework/views.py&quot;, line 505, in dispatch
      response = self.handle_exception(exc)
    File &quot;/lib/python3.8/site-packages/rest_framework/views.py&quot;, line 465, in handle_exception
      self.raise_uncaught_exception(exc)
    File &quot;/lib/python3.8/site-packages/rest_framework/views.py&quot;, line 476, in raise_uncaught_exception
      raise exc
    File &quot;/lib/python3.8/site-packages/rest_framework/views.py&quot;, line 502, in dispatch
      response = handler(request, *args, **kwargs)
    File &quot;/lib/python3.8/site-packages/rest_framework/mixins.py&quot;, line 20, in create
      headers = self.get_success_headers(serializer.data)
    File &quot;/lib/python3.8/site-packages/rest_framework/serializers.py&quot;, line 562, in data
      ret = super().data
    File &quot;/lib/python3.8/site-packages/rest_framework/serializers.py&quot;, line 260, in data
      self._data = self.to_representation(self.instance)
    File &quot;/lib/python3.8/site-packages/rest_framework/serializers.py&quot;, line 529, in to_representation
      ret[field.field_name] = field.to_representation(attribute)
    File &quot;/lib/python3.8/site-packages/rest_framework/relations.py&quot;, line 533, in to_representation
      return [
    File &quot;/lib/python3.8/site-packages/rest_framework/relations.py&quot;, line 534, in &lt;listcomp&gt;
      self.child_relation.to_representation(value)
    File &quot;/lib/python3.8/site-packages/rest_framework/relations.py&quot;, line 408, in to_representation
      raise ImproperlyConfigured(msg % self.view_name)
  django.core.exceptions.ImproperlyConfigured: Could not resolve URL for hyperlinked relationship using view name &quot;teacher-detail&quot;. You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.
  [24/Dec/2020 09:55:04] &quot;POST /appname/sections/ HTTP/1.1&quot; 500 157269
  </code></pre>