My model:
author=models.ForeignKey(User)
User id (ex. 174948) is saved to column author_id
.
In the template I show user id with {{post.author}}
I want also to show full name for that particular user.
How to do that in the template?
By using the method that does it.
{{post.author.get_full_name}}
It depends if the user object has the first and/or last name fields set.
If not (for example a new user was just created), then calling {{ post.author.get_full_name }}
may return an empty string.
This method is more reliable:
{{ post.author.get_full_name|default:post.author.username }}
Another way
{{post.author.first_name}} {{post.author.last_name}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With