[Fixed]-Django ORM Query – How to Subtract Time From Model Field?

1πŸ‘

βœ…

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'))
for result in results:
    result['max_time'] -= timedelta(minutes=60)
πŸ‘€f43d65

Leave a comment