Alpha order core models class declarations

This commit is contained in:
Christopher C. Wells 2022-05-25 20:21:53 -07:00 committed by Christopher Charbonneau Wells
parent a34f6b577d
commit 0875b6af05
2 changed files with 120 additions and 120 deletions

View File

@ -155,31 +155,31 @@ class TaggableManager(TaggitTaggableManager):
pass pass
class Pumping(models.Model): class BMI(models.Model):
model_name = "pumping" model_name = "bmi"
child = models.ForeignKey( child = models.ForeignKey(
"Child", "Child", on_delete=models.CASCADE, related_name="bmi", verbose_name=_("Child")
on_delete=models.CASCADE, )
related_name="pumping", bmi = models.FloatField(blank=False, null=False, verbose_name=_("BMI"))
verbose_name=_("Child"), date = models.DateField(
blank=False, default=timezone.localdate, null=False, verbose_name=_("Date")
) )
amount = models.FloatField(blank=False, null=False, verbose_name=_("Amount"))
time = models.DateTimeField(blank=False, null=False, verbose_name=_("Time"))
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes")) notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)
objects = models.Manager() objects = models.Manager()
class Meta: class Meta:
default_permissions = ("view", "add", "change", "delete") default_permissions = ("view", "add", "change", "delete")
ordering = ["-time"] ordering = ["-date"]
verbose_name = _("Pumping") verbose_name = _("BMI")
verbose_name_plural = _("Pumping") verbose_name_plural = _("BMI")
def __str__(self): def __str__(self):
return str(_("Pumping")) return str(_("BMI"))
def clean(self): def clean(self):
validate_time(self.time, "time") validate_date(self.date, "date")
class Child(models.Model): class Child(models.Model):
@ -350,6 +350,68 @@ class Feeding(models.Model):
validate_unique_period(Feeding.objects.filter(child=self.child), self) validate_unique_period(Feeding.objects.filter(child=self.child), self)
class HeadCircumference(models.Model):
model_name = "head_circumference"
child = models.ForeignKey(
"Child",
on_delete=models.CASCADE,
related_name="head_circumference",
verbose_name=_("Child"),
)
head_circumference = models.FloatField(
blank=False, null=False, verbose_name=_("Head Circumference")
)
date = models.DateField(
blank=False, default=timezone.localdate, null=False, verbose_name=_("Date")
)
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)
objects = models.Manager()
class Meta:
default_permissions = ("view", "add", "change", "delete")
ordering = ["-date"]
verbose_name = _("Head Circumference")
verbose_name_plural = _("Head Circumference")
def __str__(self):
return str(_("Head Circumference"))
def clean(self):
validate_date(self.date, "date")
class Height(models.Model):
model_name = "height"
child = models.ForeignKey(
"Child",
on_delete=models.CASCADE,
related_name="height",
verbose_name=_("Child"),
)
height = models.FloatField(blank=False, null=False, verbose_name=_("Height"))
date = models.DateField(
blank=False, default=timezone.localdate, null=False, verbose_name=_("Date")
)
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)
objects = models.Manager()
class Meta:
default_permissions = ("view", "add", "change", "delete")
ordering = ["-date"]
verbose_name = _("Height")
verbose_name_plural = _("Height")
def __str__(self):
return str(_("Height"))
def clean(self):
validate_date(self.date, "date")
class Note(models.Model): class Note(models.Model):
model_name = "note" model_name = "note"
child = models.ForeignKey( child = models.ForeignKey(
@ -379,6 +441,33 @@ class NapsManager(models.Manager):
return qs.filter(id__in=[obj.id for obj in qs if obj.nap]) return qs.filter(id__in=[obj.id for obj in qs if obj.nap])
class Pumping(models.Model):
model_name = "pumping"
child = models.ForeignKey(
"Child",
on_delete=models.CASCADE,
related_name="pumping",
verbose_name=_("Child"),
)
amount = models.FloatField(blank=False, null=False, verbose_name=_("Amount"))
time = models.DateTimeField(blank=False, null=False, verbose_name=_("Time"))
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
objects = models.Manager()
class Meta:
default_permissions = ("view", "add", "change", "delete")
ordering = ["-time"]
verbose_name = _("Pumping")
verbose_name_plural = _("Pumping")
def __str__(self):
return str(_("Pumping"))
def clean(self):
validate_time(self.time, "time")
class Sleep(models.Model): class Sleep(models.Model):
model_name = "sleep" model_name = "sleep"
child = models.ForeignKey( child = models.ForeignKey(
@ -625,92 +714,3 @@ class Weight(models.Model):
def clean(self): def clean(self):
validate_date(self.date, "date") validate_date(self.date, "date")
class Height(models.Model):
model_name = "height"
child = models.ForeignKey(
"Child",
on_delete=models.CASCADE,
related_name="height",
verbose_name=_("Child"),
)
height = models.FloatField(blank=False, null=False, verbose_name=_("Height"))
date = models.DateField(
blank=False, default=timezone.localdate, null=False, verbose_name=_("Date")
)
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)
objects = models.Manager()
class Meta:
default_permissions = ("view", "add", "change", "delete")
ordering = ["-date"]
verbose_name = _("Height")
verbose_name_plural = _("Height")
def __str__(self):
return str(_("Height"))
def clean(self):
validate_date(self.date, "date")
class HeadCircumference(models.Model):
model_name = "head_circumference"
child = models.ForeignKey(
"Child",
on_delete=models.CASCADE,
related_name="head_circumference",
verbose_name=_("Child"),
)
head_circumference = models.FloatField(
blank=False, null=False, verbose_name=_("Head Circumference")
)
date = models.DateField(
blank=False, default=timezone.localdate, null=False, verbose_name=_("Date")
)
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)
objects = models.Manager()
class Meta:
default_permissions = ("view", "add", "change", "delete")
ordering = ["-date"]
verbose_name = _("Head Circumference")
verbose_name_plural = _("Head Circumference")
def __str__(self):
return str(_("Head Circumference"))
def clean(self):
validate_date(self.date, "date")
class BMI(models.Model):
model_name = "bmi"
child = models.ForeignKey(
"Child", on_delete=models.CASCADE, related_name="bmi", verbose_name=_("Child")
)
bmi = models.FloatField(blank=False, null=False, verbose_name=_("BMI"))
date = models.DateField(
blank=False, default=timezone.localdate, null=False, verbose_name=_("Date")
)
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)
objects = models.Manager()
class Meta:
default_permissions = ("view", "add", "change", "delete")
ordering = ["-date"]
verbose_name = _("BMI")
verbose_name_plural = _("BMI")
def __str__(self):
return str(_("BMI"))
def clean(self):
validate_date(self.date, "date")

View File

@ -35,24 +35,6 @@ class ChildTestCase(TestCase):
self.assertEqual(models.Child.count(), 1) self.assertEqual(models.Child.count(), 1)
class PumpingTestCase(TestCase):
def setUp(self):
call_command("migrate", verbosity=0)
self.child = models.Child.objects.create(
first_name="First", last_name="Last", birth_date=timezone.localdate()
)
self.temp = models.Pumping.objects.create(
child=self.child,
time=timezone.localtime() - timezone.timedelta(days=1),
amount=98.6,
)
def test_pumping_create(self):
self.assertEqual(self.temp, models.Pumping.objects.first())
self.assertEqual(str(self.temp), "Pumping")
self.assertEqual(self.temp.amount, 98.6)
class DiaperChangeTestCase(TestCase): class DiaperChangeTestCase(TestCase):
def setUp(self): def setUp(self):
call_command("migrate", verbosity=0) call_command("migrate", verbosity=0)
@ -129,6 +111,24 @@ class NoteTestCase(TestCase):
self.assertEqual(str(note), "Note") self.assertEqual(str(note), "Note")
class PumpingTestCase(TestCase):
def setUp(self):
call_command("migrate", verbosity=0)
self.child = models.Child.objects.create(
first_name="First", last_name="Last", birth_date=timezone.localdate()
)
self.temp = models.Pumping.objects.create(
child=self.child,
time=timezone.localtime() - timezone.timedelta(days=1),
amount=98.6,
)
def test_pumping_create(self):
self.assertEqual(self.temp, models.Pumping.objects.first())
self.assertEqual(str(self.temp), "Pumping")
self.assertEqual(self.temp.amount, 98.6)
class SleepTestCase(TestCase): class SleepTestCase(TestCase):
def setUp(self): def setUp(self):
call_command("migrate", verbosity=0) call_command("migrate", verbosity=0)