Can someone point me to the right direction? Below is what I have been doing
<p>{{article.snippet}}</p>
<p>{{article.date}}</p>
<p>{{article.retrieve_by_category("web")}}</p>
I have no problems getting the date or the snippet but I keep getting the following error when trying to run article.retireve_by_category.
Could not parse the remainder: '("web")' from 'article.retrieve_by_category("web")'
Below is the code for the model:
class Article(models.Model):
category = models.CharField(max_length=100)
title = models.CharField(max_length=100)
slug = models.SlugField()
body = models.TextField()
date = models.DateTimeField(auto_now_add=True)
#add in thumbnail
def __str__(self):
return self.title
def snippet(self):
return self.body[:500] + "..."
def retrieve_by_category(self,category):
"""retrieves blogs based on their category"""
if (str(self.category) == category):
return self.category
return ''