From 5e9946ecd6ba44342cd910031db82b4e3fe27e9d Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Tue, 28 Jan 2020 22:51:47 -0800 Subject: [PATCH] Respect child if set when setting feeding defaults --- core/forms.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/forms.py b/core/forms.py index 88089a8b..bbeb61ef 100644 --- a/core/forms.py +++ b/core/forms.py @@ -42,12 +42,15 @@ def set_defaults_from_timer(kwargs): # Sets the default Feeding type to the one used in the most recent entry. def set_default_feeding_type(kwargs): instance = kwargs.get('instance', None) + initial = kwargs.get('initial', None) if not kwargs.get('initial'): kwargs.update(initial={}) - if instance is None and models.Feeding.objects.count() > 0: - kwargs['initial'].update({ - 'type': models.Feeding.objects.latest('end').type - }) + if instance is None and initial and 'child' in initial: + if models.Feeding.objects.filter(child=initial['child']).count() > 0: + kwargs['initial'].update({ + 'type': models.Feeding.objects.filter( + child=initial['child']).latest('end').type + }) return kwargs