I'd like to display a fixed-length subset of a set of related objects in a Django template. For example, imagine that I have a Car, which has related object Owner. I would like to display the three most recent owners, but also always display three entries even if there are fewer. So
Ford Fiesta AA11 1AA
1. John Smith
2. Jane Smith
3. Jenny Smith
Aston Martin DB9
1. Richard Rich
2.
3.
even if the Fiesta has had 10 owners (and the DB9 has had only one).
The naive way to do this would be
<h1>{{car.name}}</h1>
<ol>
{% for owner in car.owner_set|slice:":3" %}
<li>{{owner.name}}</li>
{% endfor %}
</ol>
but this will only display one list item if there has only been one owner.
I could also add lines like
{% if car.owner_set|length < 2 %}<li></li>{% endif %}
{% if car.owner_set|length < 3 %}<li></li>{% endif %}
but that's terrible. Is there a nicer way to do this?