mirror of https://github.com/snachodog/mybuddy.git
Add an actual duration field to relevant models.
This commit is contained in:
parent
22fbdf2868
commit
c5fc35b177
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Generated by Django 1.11.4 on 2017-08-18 18:58
|
# Generated by Django 1.11.1 on 2017-08-19 20:13
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -26,9 +26,9 @@ class Migration(migrations.Migration):
|
||||||
('slug', models.SlugField(editable=False, max_length=100, unique=True)),
|
('slug', models.SlugField(editable=False, max_length=100, unique=True)),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'verbose_name_plural': 'Children',
|
|
||||||
'ordering': ['last_name', 'first_name'],
|
'ordering': ['last_name', 'first_name'],
|
||||||
'default_permissions': ('view', 'add', 'change', 'delete'),
|
'default_permissions': ('view', 'add', 'change', 'delete'),
|
||||||
|
'verbose_name_plural': 'Children',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
@ -52,6 +52,7 @@ class Migration(migrations.Migration):
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('start', models.DateTimeField()),
|
('start', models.DateTimeField()),
|
||||||
('end', models.DateTimeField()),
|
('end', models.DateTimeField()),
|
||||||
|
('duration', models.DurationField(editable=False, null=True)),
|
||||||
('type', models.CharField(choices=[('breast milk', 'Breast milk'), ('formula', 'Formula')], max_length=255)),
|
('type', models.CharField(choices=[('breast milk', 'Breast milk'), ('formula', 'Formula')], max_length=255)),
|
||||||
('method', models.CharField(choices=[('bottle', 'Bottle'), ('left breast', 'Left breast'), ('right breast', 'Right breast')], max_length=255)),
|
('method', models.CharField(choices=[('bottle', 'Bottle'), ('left breast', 'Left breast'), ('right breast', 'Right breast')], max_length=255)),
|
||||||
('amount', models.FloatField(blank=True, null=True)),
|
('amount', models.FloatField(blank=True, null=True)),
|
||||||
|
@ -81,12 +82,13 @@ class Migration(migrations.Migration):
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('start', models.DateTimeField()),
|
('start', models.DateTimeField()),
|
||||||
('end', models.DateTimeField()),
|
('end', models.DateTimeField()),
|
||||||
|
('duration', models.DurationField(editable=False, null=True)),
|
||||||
('child', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sleep', to='core.Child')),
|
('child', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sleep', to='core.Child')),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'verbose_name_plural': 'Sleep',
|
|
||||||
'ordering': ['-start'],
|
'ordering': ['-start'],
|
||||||
'default_permissions': ('view', 'add', 'change', 'delete'),
|
'default_permissions': ('view', 'add', 'change', 'delete'),
|
||||||
|
'verbose_name_plural': 'Sleep',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
@ -96,6 +98,7 @@ class Migration(migrations.Migration):
|
||||||
('name', models.CharField(blank=True, max_length=255, null=True)),
|
('name', models.CharField(blank=True, max_length=255, null=True)),
|
||||||
('start', models.DateTimeField(auto_now_add=True)),
|
('start', models.DateTimeField(auto_now_add=True)),
|
||||||
('end', models.DateTimeField(blank=True, editable=False, null=True)),
|
('end', models.DateTimeField(blank=True, editable=False, null=True)),
|
||||||
|
('duration', models.DurationField(editable=False, null=True)),
|
||||||
('active', models.BooleanField(default=True, editable=False)),
|
('active', models.BooleanField(default=True, editable=False)),
|
||||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='timers', to=settings.AUTH_USER_MODEL)),
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='timers', to=settings.AUTH_USER_MODEL)),
|
||||||
],
|
],
|
||||||
|
@ -110,6 +113,7 @@ class Migration(migrations.Migration):
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('start', models.DateTimeField()),
|
('start', models.DateTimeField()),
|
||||||
('end', models.DateTimeField()),
|
('end', models.DateTimeField()),
|
||||||
|
('duration', models.DurationField(editable=False, null=True)),
|
||||||
('milestone', models.CharField(blank=True, max_length=255)),
|
('milestone', models.CharField(blank=True, max_length=255)),
|
||||||
('child', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tummy_time', to='core.Child')),
|
('child', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tummy_time', to='core.Child')),
|
||||||
],
|
],
|
||||||
|
|
|
@ -5,8 +5,6 @@ from django.db import models
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
from django.utils import timezone, timesince
|
from django.utils import timezone, timesince
|
||||||
|
|
||||||
from .utils import duration_string
|
|
||||||
|
|
||||||
|
|
||||||
class Child(models.Model):
|
class Child(models.Model):
|
||||||
first_name = models.CharField(max_length=255)
|
first_name = models.CharField(max_length=255)
|
||||||
|
@ -69,6 +67,7 @@ class Feeding(models.Model):
|
||||||
child = models.ForeignKey('Child', related_name='feeding')
|
child = models.ForeignKey('Child', related_name='feeding')
|
||||||
start = models.DateTimeField(blank=False, null=False)
|
start = models.DateTimeField(blank=False, null=False)
|
||||||
end = models.DateTimeField(blank=False, null=False)
|
end = models.DateTimeField(blank=False, null=False)
|
||||||
|
duration = models.DurationField(null=True, editable=False)
|
||||||
type = models.CharField(max_length=255, choices=[
|
type = models.CharField(max_length=255, choices=[
|
||||||
('breast milk', 'Breast milk'),
|
('breast milk', 'Breast milk'),
|
||||||
('formula', 'Formula'),
|
('formula', 'Formula'),
|
||||||
|
@ -88,14 +87,16 @@ class Feeding(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Feeding for {} on {} ({})'.format(
|
return 'Feeding for {} on {} ({})'.format(
|
||||||
self.child, self.end.date(), self.duration())
|
self.child, self.end.date(), self.duration)
|
||||||
|
|
||||||
def duration(self):
|
|
||||||
return duration_string(self.start, self.end)
|
|
||||||
|
|
||||||
def since(self, time=timezone.now()):
|
def since(self, time=timezone.now()):
|
||||||
return timesince.timesince(self.end, time)
|
return timesince.timesince(self.end, time)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if self.start and self.end:
|
||||||
|
self.duration = self.end - self.start
|
||||||
|
super(Feeding, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Note(models.Model):
|
class Note(models.Model):
|
||||||
child = models.ForeignKey('Child', related_name='note')
|
child = models.ForeignKey('Child', related_name='note')
|
||||||
|
@ -119,6 +120,7 @@ class Sleep(models.Model):
|
||||||
child = models.ForeignKey('Child', related_name='sleep')
|
child = models.ForeignKey('Child', related_name='sleep')
|
||||||
start = models.DateTimeField(blank=False, null=False)
|
start = models.DateTimeField(blank=False, null=False)
|
||||||
end = models.DateTimeField(blank=False, null=False)
|
end = models.DateTimeField(blank=False, null=False)
|
||||||
|
duration = models.DurationField(null=True, editable=False)
|
||||||
|
|
||||||
objects = models.Manager()
|
objects = models.Manager()
|
||||||
|
|
||||||
|
@ -129,19 +131,22 @@ class Sleep(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Sleep for {} on {} ({})'.format(
|
return 'Sleep for {} on {} ({})'.format(
|
||||||
self.child, self.end.date(), self.duration())
|
self.child, self.end.date(), self.duration)
|
||||||
|
|
||||||
def duration(self):
|
|
||||||
return duration_string(self.start, self.end)
|
|
||||||
|
|
||||||
def since(self, time=timezone.now()):
|
def since(self, time=timezone.now()):
|
||||||
return timesince.timesince(self.end, time)
|
return timesince.timesince(self.end, time)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if self.start and self.end:
|
||||||
|
self.duration = self.end - self.start
|
||||||
|
super(Sleep, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
start = models.DateTimeField(auto_now_add=True)
|
start = models.DateTimeField(auto_now_add=True)
|
||||||
end = models.DateTimeField(blank=True, null=True, editable=False)
|
end = models.DateTimeField(blank=True, null=True, editable=False)
|
||||||
|
duration = models.DurationField(null=True, editable=False)
|
||||||
active = models.BooleanField(default=True, editable=False)
|
active = models.BooleanField(default=True, editable=False)
|
||||||
user = models.ForeignKey('auth.User', related_name='timers')
|
user = models.ForeignKey('auth.User', related_name='timers')
|
||||||
|
|
||||||
|
@ -154,13 +159,11 @@ class Timer(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name or 'Timer #{}'.format(self.id)
|
return self.name or 'Timer #{}'.format(self.id)
|
||||||
|
|
||||||
def duration(self):
|
|
||||||
return duration_string(self.start, self.end or timezone.now(),
|
|
||||||
short=True)
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.active = self.end is None
|
self.active = self.end is None
|
||||||
self.name = self.name or None
|
self.name = self.name or None
|
||||||
|
if self.start and self.end:
|
||||||
|
self.duration = self.end - self.start
|
||||||
super(Timer, self).save(*args, **kwargs)
|
super(Timer, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,6 +171,7 @@ class TummyTime(models.Model):
|
||||||
child = models.ForeignKey('Child', related_name='tummy_time')
|
child = models.ForeignKey('Child', related_name='tummy_time')
|
||||||
start = models.DateTimeField(blank=False, null=False)
|
start = models.DateTimeField(blank=False, null=False)
|
||||||
end = models.DateTimeField(blank=False, null=False)
|
end = models.DateTimeField(blank=False, null=False)
|
||||||
|
duration = models.DurationField(null=True, editable=False)
|
||||||
milestone = models.CharField(max_length=255, blank=True)
|
milestone = models.CharField(max_length=255, blank=True)
|
||||||
|
|
||||||
objects = models.Manager()
|
objects = models.Manager()
|
||||||
|
@ -180,11 +184,13 @@ class TummyTime(models.Model):
|
||||||
return 'Tummy time for {} on {} ({})'.format(
|
return 'Tummy time for {} on {} ({})'.format(
|
||||||
self.child, self.end.date(), self.duration())
|
self.child, self.end.date(), self.duration())
|
||||||
|
|
||||||
def duration(self):
|
|
||||||
return duration_string(self.start, self.end)
|
|
||||||
|
|
||||||
def duration_td(self):
|
def duration_td(self):
|
||||||
return self.end - self.start
|
return self.end - self.start
|
||||||
|
|
||||||
def since(self, time=timezone.now()):
|
def since(self, time=timezone.now()):
|
||||||
return timesince.timesince(self.end, time)
|
return timesince.timesince(self.end, time)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if self.start and self.end:
|
||||||
|
self.duration = self.end - self.start
|
||||||
|
super(TummyTime, self).save(*args, **kwargs)
|
||||||
|
|
Loading…
Reference in New Issue