class Session(models.Model):
tutor = models.ForeignKey(User)
start_time = models.DateTimeField()
end_time = models.DateTimeField()
What is the best way to always prevent start_time from overlapping end_time ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, you should do this at the form level, see Cleaning and validating fields that depend on each other for instructions on how to do this, it would look like this:
Also, you can enforce it at low level in the save method or in a pre_save signal:
But that’s pretty low level so it’s not user friendly.