Reputation: 2533
I have a Django model with a User
class that inherits from AbstractUser
.
class User(AbstractUser):
pass
In the Django Admin screen, I see that the date_joined
field has month, day, year, and time precision.
I also have a Django template with the following code:
{% block header%}
<h2>{{ profile.username }}</h2>
<h3>{{ profile.date_joined }}</h3>
{% endblock %}
Not surprisingly, this renders as follows:
Foo Bar
July 4, 2021, 6:38 p.m.
What I'd like is for it to render as only the month and date, as follows:
Foo Bar
July 2021
Is is possible to convert the date_joined
field on the User
class to month and year only?
Thanks!
Upvotes: 1
Views: 323
Reputation: 477437
Yes you can format the timestamp with the |date
template filter [Django-doc]:
<h3>{{ profile.date_joined|date:"F Y" }}</h3>
Upvotes: 1