title: use searializer field in template Django Rest Framework
body: <p>I'm new to <code>Django Rest Framework</code> and writing first API application.</p>
  
  <p>my <strong>contacts/models.py</strong></p>
  
  <pre><code>class Contact(models.Model):
      user_id = models.ForeignKey(User, on_delete=models.CASCADE)
      first_name = models.CharField(max_length=100)
      last_name = models.CharField(max_length=100, blank=True, null=True)
      date_of_birth = models.DateField(blank=True, null=True)
  
      class Meta:
          db_table = 'contacts'
  
      def full_name(self):
          return self.first_name + ' ' + self.last_name
  
      def __str__(self):
          return self.full_name()
  
  
  class ContactEmail(models.Model):
      contact = models.ForeignKey(Contact, on_delete=models.CASCADE)
      email = models.EmailField()
      primary = models.BooleanField(default=False)
  
      class Meta:
          db_table = 'contact_emails'
  
      def __str__(self):
          return self.email
  </code></pre>
  
  <p><strong>contacts/searializers.py</strong></p>
  
  <pre><code>class ContactSerializer(serializers.HyperlinkedModelSerializer):
      primary_email = serializers.SerializerMethodField()
  
      class Meta:
          model = Contact
          fields = ('url', 'full_name', 'date_of_birth', 'primary_email')
  
      def get_primary_email(self, obj):
          primary_email = obj.contactemail_set.filter(primary=True).first()
  
          if primary_email:
              return primary_email.email
  
          return ''
  </code></pre>
  
  <p><strong>contacts/views.py</strong></p>
  
  <pre><code>class ContactViewSet(viewsets.ModelViewSet):
      queryset = Contact.objects.all()
      serializer_class = ContactSerializer
      permission_classes = (permissions.IsAuthenticatedOrReadOnly,
                            IsOwnerOrReadOnly,)
  
      def perform_create(self, serializer):
          serializer.save(user_id=self.request.user)
  
  class ContactList(APIView):
      renderer_classes = [TemplateHTMLRenderer]
      template_name = 'contacts/list.html'
      permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
  
      def get(self, request):
          queryset = Contact.objects.all()
          return Response({'contacts': queryset})
  </code></pre>
  
  <p>Where <code>ContactViewSet</code> is accessible by <code>http://&lt;ip&gt;:&lt;port&gt;/api/contacts</code> and <code>ContactList</code> is accessible by <code>http://&lt;ip&gt;:&lt;port&gt;/contacts</code></p>
  
  <p><code>http://&lt;ip&gt;:&lt;port&gt;/api/contacts</code> is giving <strong>primary_email</strong> in the json response but it prints nothing on using in <strong>list.html</strong> <code>{{ contact.primary_email }}</code></p>
  
  <p><strong>Can't I use Serializer fields when using **APIView</strong>?**</p>
  
  <p><strong>Do I need to rewrite the function in the <code>ContactList()</code> to get primary_email field?</strong></p>
  
  <blockquote>
    <p>Edit 2: <code>contacts/list.html</code></p>
  </blockquote>
  
  <pre><code>{% for contact in contacts %}
      &lt;h4 class="card-title"&gt;{{ contact.full_name }}&lt;/h4&gt;
      &lt;h5&gt;{{ contact.primary_email }}
      &lt;a href="{% url 'contact:detail' contact.pk %}"&gt;Click here&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
  <p>This is printing user's full name but not primary email</p>