python - Django ORM Query - How to Subtract Time From Model Field? -


i have query returns max time model field.

results = mymodel.objects.filter(                 id=pk,                 date__range=(start_time, end_time)                 ).values('my_id'                 ).annotate(max_time=max('my_date_time')) 

to point, works great. need subtract time (60 min) my_date_time field.

the convenient me if can somehow subtract time directly in html template. filters available that?

if not, there way use mysql subtime() function or python timedelta query?

suggestions , feedback appreciated!

if there similar asked/answered question, somehow missed , apologize!

edit:

yes, my_date_time field valid datetime model field.

from datetime import timedelta  results = mymodel.objects.filter(                 id=pk,                 date__range=(start_time, end_time)                 ).values('my_id'                 ).annotate(max_time=max('my_date_time')) result in results:     result['max_time'] -= timedelta(minutes=60) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -