title: How to Use get_absolute_url() with a foreign key object in Django template
body: <p>Am relatively new to django and I have searched for this problem but couldn't find a solution. Forgive me if the solution is obvious but I just can't seem to get it right.</p>
  
  <p>So, this is the issue. I have two models <strong>Parishioner</strong> and <strong>Community</strong>. Parishioner has a many-to-one relationship with Community. On the parishioner_detail page, I am trying to display the community name as a link to the community_detail page. I feel I am not using the get_absolute_url() method correctly. Any help would be appreciated.</p>
  
  <p>Models:</p>
  
  <pre><code>from django.db import models
  from django.core.urlresolvers import reverse
  
  class Community(models.Model):
      name = models.CharField(max_length=41)
      description = models.TextField()
      leader = models.CharField(max_length=41)
      email = models.EmailField()
      phone_number = models.CharField(max_length=20)
      slug = models.SlugField(max_length=31, unique=True)
  
      def __str__(self):
          return self.name
  
      def get_absolute_url(self):
          return reverse('people_community_detail', kwargs={'slug': self.slug})
  
  class Parishioner(models.Model):
      name = models.CharField(max_length=41)
      date_of_birth = models.DateField('date of birth', blank=True)
      email = models.EmailField()
      phone_number = models.CharField(max_length=20)
      start_date = models.DateField('date posted')
      societies = models.ManyToManyField(Society, blank=True, related_name='parishoners')
      communities = models.ForeignKey(Community, blank=True, related_name='parishoners')
      sacraments = models.ManyToManyField(Sacrament, blank=True, related_name='parishoners')
      slug = models.SlugField(max_length=31, unique=True)
  
      def __str__(self):
          return self.name
  
      def get_absolute_url(self):
          return reverse('people_parishioner_detail', kwargs={'slug': self.slug})
  
      class meta:
          ordering = ['name']
          verbose_name_plural = "parishioners"
  </code></pre>
  
  <p>Views:</p>
  
  <pre><code>from django.shortcuts import get_object_or_404, render, redirect
  from .models import Society, Community, Sacrament, Festival, Parishioner
  
  def community_list(request):
      return render(request, 'people/community_list.html', {'community_list': Community.objects.all()})
  
  def community_detail(request, slug):
      community = get_object_or_404(Community, slug__iexact=slug)
      return render(request, 'people/community_detail.html', {'community': community})
  
  def parishioner_list(request):
      return render(request, 'people/parishioner_list.html', {'parishioner_list': Parishioner.objects.all()})
  
  def parishioner_detail(request, slug):
      parishioner = get_object_or_404(Parishioner, slug__iexact=slug)
      return render(request, 'people/parishioner_detail.html', {'parishioner': parishioner})
  </code></pre>
  
  <p>parishioner_detail.html:</p>
  
  <pre><code>&lt;dt&gt;Community&lt;/dt&gt;
    &lt;dd&gt;&lt;a href="{{ community.get_absolute_url }}"&gt;{{ parishioner.communities|title }}&lt;/a&gt;&lt;/dd&gt;
  &lt;dt&gt;Societies&lt;/dt&gt;
    {% for society in parishioner.societies.all %}
      &lt;dd&gt;&lt;a href="{{ society.get_absolute_url }}"&gt;{{ society.name|title }}&lt;/a&gt;&lt;/dd&gt;
    {% endfor %}
  </code></pre>
  
  <p>The society name links correctly to the society_detail page but the community name links to the parishioner_detail page instead of the community_detail page. It basically reloads the page.</p>
  
  <p>Any help would be appreciated.
  Thanks.</p>