mirror of https://github.com/snachodog/mybuddy.git
feat(sleep): #323 Add napping field to the sleep model
This commit is contained in:
parent
fae764afbf
commit
c33ace2bf9
|
@ -278,7 +278,8 @@
|
||||||
"child": 1,
|
"child": 1,
|
||||||
"start": "2017-11-18T04:30:00Z",
|
"start": "2017-11-18T04:30:00Z",
|
||||||
"end": "2017-11-18T05:30:00Z",
|
"end": "2017-11-18T05:30:00Z",
|
||||||
"duration": "01:00:00"
|
"duration": "01:00:00",
|
||||||
|
"napping": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -289,7 +290,8 @@
|
||||||
"child": 1,
|
"child": 1,
|
||||||
"start": "2017-11-18T15:00:00Z",
|
"start": "2017-11-18T15:00:00Z",
|
||||||
"end": "2017-11-18T17:00:00Z",
|
"end": "2017-11-18T17:00:00Z",
|
||||||
"duration": "02:00:00"
|
"duration": "02:00:00",
|
||||||
|
"napping": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -300,7 +302,8 @@
|
||||||
"child": 1,
|
"child": 1,
|
||||||
"start": "2017-11-18T19:00:00Z",
|
"start": "2017-11-18T19:00:00Z",
|
||||||
"end": "2017-11-18T19:30:00Z",
|
"end": "2017-11-18T19:30:00Z",
|
||||||
"duration": "00:30:00"
|
"duration": "00:30:00",
|
||||||
|
"napping": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -312,7 +315,8 @@
|
||||||
"start": "2017-11-19T00:00:00Z",
|
"start": "2017-11-19T00:00:00Z",
|
||||||
"end": "2017-11-19T04:00:00Z",
|
"end": "2017-11-19T04:00:00Z",
|
||||||
"duration": "04:00:00",
|
"duration": "04:00:00",
|
||||||
"notes": "lots of squirming"
|
"notes": "lots of squirming",
|
||||||
|
"napping": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def set_napping(apps, schema_editor):
|
||||||
|
Sleeps = apps.get_model('core', 'Sleep')
|
||||||
|
for sleep in Sleeps.objects.all():
|
||||||
|
sleep.napping = sleep.nap
|
||||||
|
sleep.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('core', '0014_alter_child_slug'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='sleep',
|
||||||
|
name='napping',
|
||||||
|
field=models.BooleanField(null=True, verbose_name='Napping'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(set_napping, reverse_code=migrations.RunPython.noop),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='sleep',
|
||||||
|
name='napping',
|
||||||
|
field=models.BooleanField(verbose_name='Napping'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -299,6 +299,11 @@ class Sleep(models.Model):
|
||||||
related_name='sleep',
|
related_name='sleep',
|
||||||
verbose_name=_('Child')
|
verbose_name=_('Child')
|
||||||
)
|
)
|
||||||
|
napping = models.BooleanField(
|
||||||
|
editable=False,
|
||||||
|
null=True,
|
||||||
|
verbose_name=_('Napping')
|
||||||
|
)
|
||||||
start = models.DateTimeField(
|
start = models.DateTimeField(
|
||||||
blank=False,
|
blank=False,
|
||||||
null=False,
|
null=False,
|
||||||
|
@ -340,6 +345,7 @@ class Sleep(models.Model):
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if self.start and self.end:
|
if self.start and self.end:
|
||||||
self.duration = self.end - self.start
|
self.duration = self.end - self.start
|
||||||
|
self.napping = self.nap
|
||||||
super(Sleep, self).save(*args, **kwargs)
|
super(Sleep, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
Loading…
Reference in New Issue