Use `last()` instead of `latest()`

With `latest()`, an exception is thrown if there is one child in the database and no feeding entries.
This commit is contained in:
Christopher C. Wells 2020-02-08 14:02:47 -08:00
parent 843c7fc49b
commit 60cd90ca80
1 changed files with 1 additions and 1 deletions

View File

@ -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})