Django - Time difference right way
In the following code i'm trying to get the difference between two times, if the difference is not equal to 15 minutes throw an error.
I use the following way however i have a feeling that is not the proper one.
def clean(self):
cleaned_data = super().clean()
start_appointment = cleaned_data.get("start_appointment")
end_appointment = cleaned_data.get("end_appointment")
difference = end_appointment - start_appointment
if difference != '0:15:00':
raise forms.ValidationError("Start appointment should have a 15 minutes difference from end appointment!")
Please have a look and let me know if this is the right way.
Thank you