Answer the question
In order to leave comments, you need to log in
How to calculate the time span between two time records?
I expanded the Profile model and added two "TimeField" values there, how can I calculate and display the time interval between these two values? Is it possible to do this with "def TimeInterval" like I did below?
Models.py:
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
dayOneStart = models.TimeField(null='true', blank='true', verbose_name='Начало дня')
dayOneEnd = models.TimeField(null='true', blank='true', verbose_name='Конец дня')
def TimeInterval(self):
return(self.dayOneEnd - self.dayOneStart)
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question