Respect child if set when setting feeding defaults

This commit is contained in:
Christopher C. Wells 2020-01-28 22:51:47 -08:00 committed by Christopher Charbonneau Wells
parent b31d9194d9
commit 5e9946ecd6
1 changed files with 7 additions and 4 deletions

View File

@ -42,12 +42,15 @@ def set_defaults_from_timer(kwargs):
# Sets the default Feeding type to the one used in the most recent entry. # Sets the default Feeding type to the one used in the most recent entry.
def set_default_feeding_type(kwargs): def set_default_feeding_type(kwargs):
instance = kwargs.get('instance', None) instance = kwargs.get('instance', None)
initial = kwargs.get('initial', None)
if not kwargs.get('initial'): if not kwargs.get('initial'):
kwargs.update(initial={}) kwargs.update(initial={})
if instance is None and models.Feeding.objects.count() > 0: if instance is None and initial and 'child' in initial:
kwargs['initial'].update({ if models.Feeding.objects.filter(child=initial['child']).count() > 0:
'type': models.Feeding.objects.latest('end').type kwargs['initial'].update({
}) 'type': models.Feeding.objects.filter(
child=initial['child']).latest('end').type
})
return kwargs return kwargs