Skip to content
Advertisement

model IntegerField() to django-template with ordinal

I have a model with IntegerField()

class Room(models.Model):
    type = models.CharField(max_length=50)
    floor = models.IntegerField()

And i would like it to display in a template with ordinal suffix.

{% for room in rooms %}
    <div>
        <p> {{ room.type }}</p>
        <p> {{ room.floor }} </p>
    </div>
{% endfor %}

I would like the floor output like this.

1st, 2nd, 3rd, 4th... 10th.. 12th.. 13th.. 15th...

Advertisement

Answer

You can use ordinal function from django.contrib.humanize package

Advertisement