Prototype String class in CoffeeScript
String.prototype.truncatechars = (len)->
this.substring(0, len)
or in JavaScript
String.prototype.truncatechars function(len){
return this.substring(0, len);
}
Rewrite your django template from
<p>{ text|truncatechars: 20}}</p>
where {{ }} rendered by django template.
to
<p>{{ text.truncatechar(20) }}</p>
where {{ }} use AngularJS.