title: django using another field instead of id in the url template tag
body: <p>I am using Django 1.5</p>
  
  <p>I have this block of code in a html file</p>
  
  <pre><code>{% for p in latest_posts %}
        &lt;li&gt;&lt;a href="{% url 'blog:detail' p.id %}"&gt;{{p.title}}&lt;/a&gt;&lt;/li&gt;
  {% endfor %}
  </code></pre>
  
  <p>If i change p.id to p.title</p>
  
  <pre><code>{% for p in latest_posts %}
        &lt;li&gt;&lt;a href="{% url 'blog:detail' p.title %}"&gt;{{p.title}}&lt;/a&gt;&lt;/li&gt;
  {% endfor %}
  </code></pre>
  
  <p>then I get the following error</p>
  
  <pre><code>Reverse for 'detail' with arguments '(u'Second post',)' and keyword arguments '{}' not found.
  </code></pre>
  
  <p>I want the url to be /title and not /id. </p>
  
  <p>This is my urls.py file</p>
  
  <pre><code>urlpatterns = patterns ('',
  
      url(r'^(?P&lt;title&gt;\w+)/$',
              PostDetailView.as_view(),
              name = 'detail'
          ),
  )
  </code></pre>
  
  <p>Should I just use get_absolute_url?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I added the slug field but it still doesn't work</p>
  
  <pre><code>{% url 'blog:detail' p.slug %}
  </code></pre>
  
  <p>The error I get is</p>
  
  <pre><code>Reverse for 'detail' with arguments '(u'third-post',)' and keyword arguments '{}' not found.
  </code></pre>
  
  <p><strong>Post model</strong></p>
  
  <pre><code>class Post(models.Model):
      title = models.CharField(max_length = 225)
      body = models.TextField()
      slug = models.SlugField()
      pub_date = models.DateTimeField()
      modified = models.DateTimeField(auto_now=True)
      created = models.DateTimeField(auto_now_add=True)
  
      def __unicode__(self):
          return self.title
  </code></pre>
  
  <p>The admin is updated</p>
  
  <pre><code>class PostAdmin(admin.ModelAdmin):
      prepopulated_fields = {"slug" : ("title",)}
  
  
  admin.site.register(Post, PostAdmin)
  </code></pre>
  
  <p>If this works </p>
  
  <pre><code>&lt;a href="{% url 'blog:detail' p.id %}"&gt;{{p.title}}&lt;/a&gt;
  </code></pre>
  
  <p>why doesn't this work</p>
  
  <pre><code>&lt;li&gt;&lt;a href="{% url 'blog:detail' p.slug %}"&gt;{{p.title}}&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p><strong>update</strong></p>
  
  <p>PostDetailView</p>
  
  <pre><code>class PostDetailView(DetailView):
  
      template_name = 'blogapp/post/detail.html'
  
      def get_object(self):
          return get_object_or_404(Post, slug__iexact = self.kwargs['slug'])
  </code></pre>