3๐
โ
You can write a custom template filter for it.
from django import template
register = template.Library()
@register.filter
def last_name_initial(value):
"""
Returns the first character of lastname in lowercase for a given name
"""
last_name = value.split()[-1] # get the last name from value
return lastname[0].lower() # get the first letter of last name in lower case
In the template, you can use it like:
{{ name|last_name_initial }}
๐คRahul Gupta
Source:stackexchange.com