mirror of https://github.com/snachodog/mybuddy.git
Add a "since" calculated field to existing models with time data.
This commit is contained in:
parent
c908ae6e2b
commit
0ed0ae1a94
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
from django.utils import timezone
|
from django.utils import timezone, timesince
|
||||||
|
|
||||||
from .utils import duration_string
|
from .utils import duration_string
|
||||||
|
|
||||||
|
@ -51,6 +51,9 @@ class DiaperChange(models.Model):
|
||||||
return 'Diaper change for {} on {}'.format(
|
return 'Diaper change for {} on {}'.format(
|
||||||
self.child, self.time.date())
|
self.child, self.time.date())
|
||||||
|
|
||||||
|
def since(self, time=timezone.now()):
|
||||||
|
return timesince.timesince(self.time, time)
|
||||||
|
|
||||||
|
|
||||||
class Feeding(models.Model):
|
class Feeding(models.Model):
|
||||||
child = models.ForeignKey('Child', related_name='feeding')
|
child = models.ForeignKey('Child', related_name='feeding')
|
||||||
|
@ -80,6 +83,9 @@ class Feeding(models.Model):
|
||||||
def duration(self):
|
def duration(self):
|
||||||
return duration_string(self.start, self.end)
|
return duration_string(self.start, self.end)
|
||||||
|
|
||||||
|
def since(self, time=timezone.now()):
|
||||||
|
return timesince.timesince(self.end, time)
|
||||||
|
|
||||||
|
|
||||||
class Note(models.Model):
|
class Note(models.Model):
|
||||||
child = models.ForeignKey('Child', related_name='note')
|
child = models.ForeignKey('Child', related_name='note')
|
||||||
|
@ -95,6 +101,9 @@ class Note(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Note about {} on {}'.format(self.child, self.time.date())
|
return 'Note about {} on {}'.format(self.child, self.time.date())
|
||||||
|
|
||||||
|
def since(self, time=timezone.now()):
|
||||||
|
return timesince.timesince(self.time, time)
|
||||||
|
|
||||||
|
|
||||||
class Sleep(models.Model):
|
class Sleep(models.Model):
|
||||||
child = models.ForeignKey('Child', related_name='sleep')
|
child = models.ForeignKey('Child', related_name='sleep')
|
||||||
|
@ -115,6 +124,9 @@ class Sleep(models.Model):
|
||||||
def duration(self):
|
def duration(self):
|
||||||
return duration_string(self.start, self.end)
|
return duration_string(self.start, self.end)
|
||||||
|
|
||||||
|
def since(self, time=timezone.now()):
|
||||||
|
return timesince.timesince(self.end, time)
|
||||||
|
|
||||||
|
|
||||||
class Timer(models.Model):
|
class Timer(models.Model):
|
||||||
name = models.CharField(max_length=255, null=True, blank=True)
|
name = models.CharField(max_length=255, null=True, blank=True)
|
||||||
|
@ -160,3 +172,6 @@ class TummyTime(models.Model):
|
||||||
|
|
||||||
def duration(self):
|
def duration(self):
|
||||||
return duration_string(self.start, self.end)
|
return duration_string(self.start, self.end)
|
||||||
|
|
||||||
|
def since(self, time=timezone.now()):
|
||||||
|
return timesince.timesince(self.end, time)
|
||||||
|
|
Loading…
Reference in New Issue