First, you need to split the given text into sentences, you can use the function provided in this answer
Next, register your custom template tag that uses the above function, and here you go:
from django import template
from django.template.defaultfilters import stringfilter
from <your utils package> import split_into_sentences
register = template.Library()
@register.filter
@stringfilter
def truncate_sentences(value, length=3):
sentences = split_into_sentences(value)
return ' '.join(sentences[:length])
Then simply use the custom template tag in your template:
{{ post.content|truncate_sentences:3 }}