Django Numerical Positions

November 12, 2010

I wanted to convert the position at a competition into 1st, 2nd, 3rd, 4th etc. Django makes this easy with the humanize template filters.

First of all, you need to add the humanize application to your INSTALLED_APPS:


Next, add:

{% load humanize %}

to the top of your template, then use the ordinal filter:

<h3>{{result.results_position|ordinal}} {{result.contest_event.event_date}} {{}}</h3>

On the resulting HTML, this will show as