Make sure there is at least one Feeding object before attempting to preset the type for a new entry.

This commit is contained in:
Christopher Charbonneau Wells 2018-04-07 06:35:35 -07:00
parent 382d106c28
commit 7c980150a4
1 changed files with 1 additions and 1 deletions

View File

@ -41,7 +41,7 @@ def set_default_feeding_type(kwargs):
instance = kwargs.get('instance', None) instance = kwargs.get('instance', 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.latest('end'): if instance is None and models.Feeding.objects.count() > 0:
kwargs['initial'].update({ kwargs['initial'].update({
'type': models.Feeding.objects.latest('end').type 'type': models.Feeding.objects.latest('end').type
}) })