In my django templates i have a list of objects which is rendered as follows:
<li class="keys">
{% for key in job.key_list|slice:":2" %}
{% if not forloop.last %}
<a href="/keys/{{ key.id }}/{{ key }}/">{{ key }}</a>,
{% else %}
<a href="/keys/{{ key.id }}/{{ key }}/">{{ key }}</a>
{% endif %}
{% endfor %}
</li>
This outputs the list as:
some_key, some_key_two
I want to truncate the number of characters to 20 but on the whole list. So that it renders something like:
some_key, some_key_t...
I am aware about the truncatechars
and truncatewords
filters available in django but they work on a string variable within the template.
How do i go about implementing this functionality ?