title: How to cache a model method in django?
body: <p>I have this model:</p>
  
  <pre><code>class Article(models.Model):
      title = models.CharField(max_length=300, blank=False)
      body = models.TextField(max_length=10000, blank=False)
      created = models.DateTimeField(auto_now_add=True)
  
  
      def last_post(self):
          if self.post_set.count():
              return self.post_set.order_by("-created")[0]
  </code></pre>
  
  <p>I have noticed that the <code>last_post</code> creates a very costly and frequently run query. So I want to cache it for 5 minutes. </p>
  
  <p>I know how to cache a queryset in views but <code>last_post</code> bypasses views and is directly called in template. So appreciate your hints on how to cache it.</p>