diff --git a/babybuddy/fixtures/tests.json b/babybuddy/fixtures/tests.json index 24d12180..a668f715 100644 --- a/babybuddy/fixtures/tests.json +++ b/babybuddy/fixtures/tests.json @@ -278,7 +278,8 @@ "child": 1, "start": "2017-11-18T04:30:00Z", "end": "2017-11-18T05:30:00Z", - "duration": "01:00:00" + "duration": "01:00:00", + "napping": false } }, { @@ -289,7 +290,8 @@ "child": 1, "start": "2017-11-18T15:00:00Z", "end": "2017-11-18T17:00:00Z", - "duration": "02:00:00" + "duration": "02:00:00", + "napping": true } }, { @@ -300,7 +302,8 @@ "child": 1, "start": "2017-11-18T19:00: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", "end": "2017-11-19T04:00:00Z", "duration": "04:00:00", - "notes": "lots of squirming" + "notes": "lots of squirming", + "napping": false } }, { diff --git a/core/migrations/0015_add_nap_field_for_sleep.py b/core/migrations/0015_add_nap_field_for_sleep.py new file mode 100644 index 00000000..aee3f332 --- /dev/null +++ b/core/migrations/0015_add_nap_field_for_sleep.py @@ -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'), + ), + ] diff --git a/core/models.py b/core/models.py index 8ef106d4..04be21d2 100644 --- a/core/models.py +++ b/core/models.py @@ -299,6 +299,11 @@ class Sleep(models.Model): related_name='sleep', verbose_name=_('Child') ) + napping = models.BooleanField( + editable=False, + null=True, + verbose_name=_('Napping') + ) start = models.DateTimeField( blank=False, null=False, @@ -340,6 +345,7 @@ class Sleep(models.Model): def save(self, *args, **kwargs): if self.start and self.end: self.duration = self.end - self.start + self.napping = self.nap super(Sleep, self).save(*args, **kwargs) def clean(self):