From 60cd90ca80f4771b8b98372368c7b3b38d1563e2 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sat, 8 Feb 2020 14:02:47 -0800 Subject: [PATCH] Use `last()` instead of `latest()` With `latest()`, an exception is thrown if there is one child in the database and no feeding entries. --- core/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/forms.py b/core/forms.py index c8cf530b..6e9e0341 100644 --- a/core/forms.py +++ b/core/forms.py @@ -46,7 +46,7 @@ def set_initial_values(kwargs, form_type): # Set initial type value for Feeding instance based on last type used. if form_type == FeedingForm and 'child' in kwargs['initial']: last_feeding = models.Feeding.objects.filter( - child=kwargs['initial']['child']).latest('end') + child=kwargs['initial']['child']).order_by('end').last() if last_feeding: kwargs['initial'].update({'type': last_feeding.type})