Reputation: 535
class Result(models.Model):
starttime = models.TimeField(blank=True)
endtime = models.TimeField(blank=True)
duration = models.DurationField(blank=True)
def save(self, *args, **kwargs):
self.duration = self.endtime - self.starttime
super(Result, self).save(*args, **kwargs)
What's the correct way of doing this? I get:
Upvotes: 1
Views: 450
Reputation: 599480
You can't subtract standalone times from each other. For example, what would "12pm - 3pm" be?
You can subtract datetimes, since they represent actual points in time. You should probably use DateTimeField instead.
Upvotes: 2