0π
β
I donβt think this is possible in templates. As you do not only want 5 comments but you also want to order them (latest 5). You can add a method in your BaseRecipe
model class to get recent comments.
class BaseRecipe(models.Model):
def get_recent_comments(self, n=5):
return self.comment_link.all().order_by('-id')[:n]
Then call this method in your template
{% for comment in object.get_recent_comments %}
π€Muhammad Tahir
- Filtering Many-to-many field in Rest Framework
- Edit and update HTML datatable Django
- Why Django return form is invalid?
Source:stackexchange.com