@library.global_function
def display_name(user):
 try:
  profile = Profile.objects.get(user_id=user.id)
 except (Profile.DoesNotExist, AttributeError):
  return user.username
 return (profile.display_name if profile else user.username)

@ library . global_function def display_name ( user ) : try : profile = Profile . objects . get ( user_id = user . id ) except ( Profile . DoesNotExist , AttributeError ) : return user . username return ( profile . display_name if profile else user . username )
return a display name if set .