This is a filter to shorten the natural time value obtained using naturaltime function from humanize.
1
2
3
4
5
6
7
8
9
10
11
12
13
#In templatetag file , say file_tags.pyfromdjangoimporttemplateregister=template.Library()@register.filterdefshorten_naturaltime(naturaltime):naturaltime=naturaltime.replace('minutes','m').replace('hours','h').replace('days','d')naturaltime=naturaltime.replace('months','mon').replace('weeks','w').replace('week','w')returnnaturaltime#In Usage file{%loadfile_tags%}{{start_time|naturaltime|shorten_naturaltime}}#where start_time is the datetime object to be modified
Comments
Please login first before commenting.