0

i have been trying to figure how how do I do a simple subtraction between two time fields and show the total time on the admin page as well for confirmation before saving. example would be actual time of arrival - actual time of departure = total flight time

atd = models.TimeField(null=True, default='00:00:00') ata = models.TimeField(null=True, default='00:00:00')

trying to get atd - ata to get the total flight time, how do i do this in django.

thanks for your help!

1 Answers1

0

You can try the following

import datetime
time1 = datetime.datetime.strptime(atd,'%H:%M:%S')
time2 = datetime.datetime.strptime(ata,'%H:%M:%S')
difference = time2-time1
Arvind Kumar
  • 913
  • 10
  • 23
  • Is there anyway i am able to add this to my models on the admin page? thanks :) – Alton Tan May 30 '20 at 08:32
  • I think, You can not display it in models, as this is not model. This is just a calculated field. If you want to show it on admin models, store this info in the database under a model – Arvind Kumar May 30 '20 at 08:42
  • is there a method for me to store this info in the database? i do it in the models.py file? thanks alot for your help – Alton Tan Jun 02 '20 at 10:00