Add generic "Amount" field to Diaper Change model (#77)

This commit is contained in:
Christopher C. Wells 2020-01-26 13:22:20 -08:00
parent 6bf63f89b1
commit a8abfb725f
6 changed files with 31 additions and 3 deletions

View File

@ -90,7 +90,7 @@ class ChildDeleteForm(forms.ModelForm):
class DiaperChangeForm(forms.ModelForm): class DiaperChangeForm(forms.ModelForm):
class Meta: class Meta:
model = models.DiaperChange model = models.DiaperChange
fields = ['child', 'time', 'wet', 'solid', 'color'] fields = ['child', 'time', 'wet', 'solid', 'color', 'amount']
widgets = { widgets = {
'time': forms.DateTimeInput(attrs={ 'time': forms.DateTimeInput(attrs={
'class': 'datetimepicker-input', 'class': 'datetimepicker-input',

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.2 on 2020-01-26 21:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0008_auto_20190607_1422'),
]
operations = [
migrations.AddField(
model_name='diaperchange',
name='amount',
field=models.FloatField(blank=True, null=True, verbose_name='Amount'),
),
]

View File

@ -139,6 +139,7 @@ class DiaperChange(models.Model):
max_length=255, max_length=255,
verbose_name=_('Color') verbose_name=_('Color')
) )
amount = models.FloatField(blank=True, null=True, verbose_name=_('Amount'))
objects = models.Manager() objects = models.Manager()

View File

@ -18,6 +18,7 @@
<th class="text-center">{% trans "Wet" %}</th> <th class="text-center">{% trans "Wet" %}</th>
<th class="text-center">{% trans "Solid" %}</th> <th class="text-center">{% trans "Solid" %}</th>
<th>{% trans "Color" %}</th> <th>{% trans "Color" %}</th>
<th>{% trans "Amount" %}</th>
<th>{% trans "Time" %}</th> <th>{% trans "Time" %}</th>
<th class="text-center">{% trans "Actions" %}</th> <th class="text-center">{% trans "Actions" %}</th>
</tr> </tr>
@ -29,6 +30,7 @@
<td class="text-center">{{ change.wet|bool_icon }}</td> <td class="text-center">{{ change.wet|bool_icon }}</td>
<td class="text-center">{{ change.solid|bool_icon }}</td> <td class="text-center">{{ change.solid|bool_icon }}</td>
<td>{{ change.get_color_display }}</td> <td>{{ change.get_color_display }}</td>
<td>{{ change.amount|default_if_none:"" }}</td>
<td>{{ change.time }}</td> <td>{{ change.time }}</td>
<td class="text-center"> <td class="text-center">
<div class="btn-group btn-group-sm" role="group" aria-label="{% trans "Actions" %}"> <div class="btn-group btn-group-sm" role="group" aria-label="{% trans "Actions" %}">

View File

@ -58,7 +58,8 @@ class FormsTestCase(TestCase):
'time': '2000-01-01 1:01', 'time': '2000-01-01 1:01',
'wet': 1, 'wet': 1,
'solid': 1, 'solid': 1,
'color': 'black' 'color': 'black',
'amount': 0.45
} }
entry = models.DiaperChange.objects.first() entry = models.DiaperChange.objects.first()

View File

@ -37,12 +37,18 @@ class DiaperChangeTestCase(TestCase):
time=timezone.localtime() - timezone.timedelta(days=1), time=timezone.localtime() - timezone.timedelta(days=1),
wet=1, wet=1,
solid=1, solid=1,
color='black' color='black',
amount=1.25
) )
def test_diaperchange_create(self): def test_diaperchange_create(self):
self.assertEqual(self.change, models.DiaperChange.objects.first()) self.assertEqual(self.change, models.DiaperChange.objects.first())
self.assertEqual(str(self.change), 'Diaper Change') self.assertEqual(str(self.change), 'Diaper Change')
self.assertEqual(self.change.child, self.child)
self.assertTrue(self.change.wet)
self.assertTrue(self.change.solid)
self.assertEqual(self.change.color, 'black')
self.assertEqual(self.change.amount, 1.25)
def test_diaperchange_attributes(self): def test_diaperchange_attributes(self):
self.assertListEqual( self.assertListEqual(