O
O
orbit0702019-05-26 14:26:02
Django
orbit070, 2019-05-26 14:26:02

How to subtract another (DateTimeField) from the current date in template?

The user filled out the form and specified some date through the DateTimeField field, everything was saved to the database.
On another page, I want to display all users and for each, instead of the selected date, show "Current_date - user_selected_date" in years.
Google issues solutions via import datetime, but all this is in views.py, and I need to do this in a template (templates.py). In a template it is impossible to do import datetime? Please tell me how can I do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-05-26
@orbit070

It is not necessary to carry out calculations in the template, this violates MVC / MVT. Either do the necessary calculations in the view and pass it to the template context, or write a template tag that performs such calculations, and it would be quite good to create a calculated property of the model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question