Customization: Extra filters and tags

  1. Custom managers
  2. Customization
  3. Custom tags

The topics page ought to say how many posts are in that topic. Add this to topic.html:

{% block content %}

<p>The Old Dead Guys have posted {{ postings.count }} time{{ postings|pluralize }} on <em>{{ topic.title }}</em>.</p>

{{ block.super }}

{% endblock %}

Here, we’re not just overriding the content block, we’re modifying it: “block.super” uses the parent block’s content as well.

When we get to ten or more posts, it will be fine to use numbers instead of words, but it would be nice to use words “two times” instead of “2 times” when the numbers are nine or below.

There are a collection of extra filters for “humanizing” numbers, but we need to specifically load them into our template. In your file, add django.contrib.humanize to INSTALLED_APPS:





At the top of topic.html, add:

{% load humanize %}

And then add the “apnumber” filter to postings.count:

<p>The Old Dead Guys have posted {{ postings.count|apnumber }} time{{ postings|pluralize }} on <em>{{ topic.title }}</em>.</p>

If you need to generate random text, look at the “django.contrib.webdesign” for a lorem ipsum tag:

  1. Custom managers
  2. Customization
  3. Custom tags