2017-08-13 15:20:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-08-11 18:32:02 +00:00
|
|
|
from django.db import models
|
2017-08-16 22:33:02 +00:00
|
|
|
from django.utils import timezone
|
2017-08-11 18:32:02 +00:00
|
|
|
|
2017-08-13 15:59:14 +00:00
|
|
|
from .utils import duration_string
|
|
|
|
|
2017-08-13 14:48:16 +00:00
|
|
|
|
2017-08-16 12:49:58 +00:00
|
|
|
class Child(models.Model):
|
2017-08-13 14:48:16 +00:00
|
|
|
first_name = models.CharField(max_length=255)
|
|
|
|
last_name = models.CharField(max_length=255)
|
|
|
|
birth_date = models.DateField(blank=False, null=False)
|
|
|
|
|
|
|
|
objects = models.Manager()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_permissions = ('view', 'add', 'change', 'delete')
|
|
|
|
ordering = ['last_name', 'first_name']
|
2017-08-16 12:49:58 +00:00
|
|
|
verbose_name_plural = 'Children'
|
2017-08-13 14:48:16 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return '{} {}'.format(self.first_name, self.last_name)
|
|
|
|
|
|
|
|
|
2017-08-13 19:51:25 +00:00
|
|
|
class DiaperChange(models.Model):
|
2017-08-16 14:29:53 +00:00
|
|
|
child = models.ForeignKey('Child', related_name='diaper_change')
|
2017-08-13 19:51:25 +00:00
|
|
|
time = models.DateTimeField(blank=False, null=False)
|
|
|
|
wet = models.BooleanField()
|
|
|
|
solid = models.BooleanField()
|
|
|
|
color = models.CharField(max_length=255, blank=True, choices=[
|
|
|
|
('black', 'Black'),
|
|
|
|
('brown', 'Brown'),
|
|
|
|
('green', 'Green'),
|
|
|
|
('yellow', 'Yellow'),
|
|
|
|
])
|
|
|
|
|
|
|
|
objects = models.Manager()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_permissions = ('view', 'add', 'change', 'delete')
|
|
|
|
ordering = ['-time']
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-08-16 22:33:02 +00:00
|
|
|
return 'Diaper change for {} on {}'.format(
|
|
|
|
self.child, self.time.date())
|
2017-08-13 19:51:25 +00:00
|
|
|
|
|
|
|
|
2017-08-13 15:59:14 +00:00
|
|
|
class Feeding(models.Model):
|
2017-08-16 14:29:53 +00:00
|
|
|
child = models.ForeignKey('Child', related_name='feeding')
|
2017-08-13 15:59:14 +00:00
|
|
|
start = models.DateTimeField(blank=False, null=False)
|
|
|
|
end = models.DateTimeField(blank=False, null=False)
|
|
|
|
type = models.CharField(max_length=255, choices=[
|
|
|
|
('breast milk', 'Breast milk'),
|
|
|
|
('formula', 'Formula'),
|
|
|
|
])
|
|
|
|
method = models.CharField(max_length=255, choices=[
|
|
|
|
('bottle', 'Bottle'),
|
|
|
|
('left breast', 'Left breast'),
|
|
|
|
('right breast', 'Right breast'),
|
|
|
|
])
|
2017-08-16 22:07:25 +00:00
|
|
|
amount = models.FloatField(blank=True, null=True)
|
2017-08-13 15:59:14 +00:00
|
|
|
|
|
|
|
objects = models.Manager()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_permissions = ('view', 'add', 'change', 'delete')
|
|
|
|
ordering = ['-start']
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-08-13 16:04:39 +00:00
|
|
|
return 'Feeding for {} on {} ({})'.format(
|
2017-08-16 14:29:53 +00:00
|
|
|
self.child, self.end.date(), self.duration())
|
2017-08-13 15:59:14 +00:00
|
|
|
|
|
|
|
def duration(self):
|
|
|
|
return duration_string(self.start, self.end)
|
|
|
|
|
|
|
|
|
2017-08-13 20:48:16 +00:00
|
|
|
class Note(models.Model):
|
2017-08-16 14:29:53 +00:00
|
|
|
child = models.ForeignKey('Child', related_name='note')
|
2017-08-13 20:48:16 +00:00
|
|
|
note = models.TextField()
|
|
|
|
time = models.DateTimeField(auto_now=True)
|
|
|
|
|
|
|
|
objects = models.Manager()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_permissions = ('view', 'add', 'change', 'delete')
|
|
|
|
ordering = ['-time']
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-08-16 14:29:53 +00:00
|
|
|
return 'Note about {} on {}'.format(self.child, self.time.date())
|
2017-08-13 20:48:16 +00:00
|
|
|
|
|
|
|
|
2017-08-13 14:48:16 +00:00
|
|
|
class Sleep(models.Model):
|
2017-08-16 14:29:53 +00:00
|
|
|
child = models.ForeignKey('Child', related_name='sleep')
|
2017-08-13 14:48:16 +00:00
|
|
|
start = models.DateTimeField(blank=False, null=False)
|
|
|
|
end = models.DateTimeField(blank=False, null=False)
|
|
|
|
|
|
|
|
objects = models.Manager()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_permissions = ('view', 'add', 'change', 'delete')
|
|
|
|
ordering = ['-start']
|
|
|
|
verbose_name_plural = 'Sleep'
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-08-13 16:04:39 +00:00
|
|
|
return 'Sleep for {} on {} ({})'.format(
|
2017-08-16 14:29:53 +00:00
|
|
|
self.child, self.end.date(), self.duration())
|
2017-08-13 15:20:09 +00:00
|
|
|
|
|
|
|
def duration(self):
|
2017-08-13 15:59:14 +00:00
|
|
|
return duration_string(self.start, self.end)
|
2017-08-13 19:05:44 +00:00
|
|
|
|
|
|
|
|
2017-08-16 22:33:02 +00:00
|
|
|
class Timer(models.Model):
|
2017-08-18 02:52:41 +00:00
|
|
|
name = models.CharField(max_length=255, null=True, blank=True)
|
2017-08-18 05:01:37 +00:00
|
|
|
start = models.DateTimeField(auto_now_add=True)
|
2017-08-16 22:33:02 +00:00
|
|
|
end = models.DateTimeField(blank=True, null=True, editable=False)
|
|
|
|
active = models.BooleanField(default=True, editable=False)
|
2017-08-17 18:42:44 +00:00
|
|
|
user = models.ForeignKey('auth.User', related_name='timers')
|
2017-08-16 22:33:02 +00:00
|
|
|
|
|
|
|
objects = models.Manager()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_permissions = ('view', 'add', 'change', 'delete')
|
|
|
|
ordering = ['active', '-start']
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-08-18 02:52:41 +00:00
|
|
|
return self.name or 'Timer #{}'.format(self.id)
|
2017-08-16 22:33:02 +00:00
|
|
|
|
|
|
|
def duration(self):
|
2017-08-16 23:08:52 +00:00
|
|
|
return duration_string(self.start, self.end or timezone.now(),
|
|
|
|
short=True)
|
2017-08-16 22:33:02 +00:00
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
self.active = self.end is None
|
2017-08-18 02:52:41 +00:00
|
|
|
self.name = self.name or None
|
2017-08-16 22:33:02 +00:00
|
|
|
super(Timer, self).save(*args, **kwargs)
|
|
|
|
|
|
|
|
|
2017-08-13 19:05:44 +00:00
|
|
|
class TummyTime(models.Model):
|
2017-08-16 14:29:53 +00:00
|
|
|
child = models.ForeignKey('Child', related_name='tummy_time')
|
2017-08-13 19:05:44 +00:00
|
|
|
start = models.DateTimeField(blank=False, null=False)
|
|
|
|
end = models.DateTimeField(blank=False, null=False)
|
|
|
|
milestone = models.CharField(max_length=255, blank=True)
|
|
|
|
|
|
|
|
objects = models.Manager()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_permissions = ('view', 'add', 'change', 'delete')
|
|
|
|
ordering = ['-start']
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'Tummy time for {} on {} ({})'.format(
|
2017-08-16 14:29:53 +00:00
|
|
|
self.child, self.end.date(), self.duration())
|
2017-08-13 19:05:44 +00:00
|
|
|
|
|
|
|
def duration(self):
|
|
|
|
return duration_string(self.start, self.end)
|