title: How to get the previous and next post in my Django blog?
body: <p>I know Django have get_previous_by_FOO and get_next_by_FOO methods but I don't know how to use them in my templates and views. So, please help me to make this two methods work for my project.</p>
  
  <p>I'm running <code>Django1.7</code> and <code>Python2.7</code> and my app name is <code>blog</code>
  Here is my corresponding files:</p>
  
  <p><strong>blog/views.py</strong></p>
  
  <pre><code>def view_post(request, slug):
      post = get_object_or_404(Post, slug=slug)
      return render_to_response('blog/blog_post.html',
              {
                  'post':post,
              },
              context_instance=RequestContext(request))
  
  
  
  class PublishedPostMixin(object):
      def get_queryset(self):
          return self.model.objects.live()
  
  
  class PostDetailView(PublishedPostMixin,DetailView):
      model = Post
  </code></pre>
  
  <p><strong>blog/models.py</strong></p>
  
  <pre><code>class Post(models.Model):
      created_at = models.DateTimeField(auto_now_add=True, editable=False)
      updated_at = models.DateTimeField(auto_now=True, editable=False)
      title = models.CharField(max_length=255)
      slug = models.SlugField(max_length=255,unique=True) 
      content = MarkdownField()
      published = models.BooleanField(default=True)
      author = models.ForeignKey(User, related_name="posts")
      tags = models.ManyToManyField(Tag)
  
      class Meta:
          ordering = ["-created_at", "title"]
  
      def __unicode__(self):
          return self.title
  
      def save(self, *args, ** kwargs):
          if not self.slug:
              self.slug = slugify(self.title) #title become the slug
          super(Post, self).save(*args,**kwargs)
  
      @models.permalink
      def get_absolute_url(self):
          return ("blog:detail",(),{'slug':self.slug
                              })
  </code></pre>
  
  <p><strong>blog/urls.py</strong></p>
  
  <pre><code>urlpatterns = patterns('',
      url(r"^(?P&lt;slug&gt;[\w-]+)/$",view_post, name="detail"),
  )
  </code></pre>
  
  <h1><strong>Templates</strong></h1>
  
  <pre><code>&lt;p&gt;
     {{ post.content|markdown }}
  &lt;/p&gt;
  &lt;ul class="pager"&gt;
     &lt;li class="previous"&gt;
        &lt;a href="{{post.get_previous_by_created_at}}"&gt;&amp;larr; Previous Posts&lt;/a&gt;
     &lt;/li&gt;
     &lt;li class="next"&gt;
        &lt;a href="{{post.get_next_by_created_at}}"&gt;Next Posts &amp;rarr;&lt;/a&gt;
     &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>