mirror of https://github.com/snachodog/mybuddy.git
Prepopulate method for formula types (#127).
This commit is contained in:
parent
4d74df27d9
commit
4978208d7f
|
@ -43,12 +43,16 @@ def set_initial_values(kwargs, form_type):
|
|||
'end': timer.end or timezone.now()
|
||||
})
|
||||
|
||||
# Set initial type value for Feeding instance based on last type used.
|
||||
# Set type and method values for Feeding instance based on last feed.
|
||||
if form_type == FeedingForm and 'child' in kwargs['initial']:
|
||||
last_feeding = models.Feeding.objects.filter(
|
||||
child=kwargs['initial']['child']).order_by('end').last()
|
||||
if last_feeding:
|
||||
kwargs['initial'].update({'type': last_feeding.type})
|
||||
last_type = last_feeding.type
|
||||
last_feed_args = {'type': last_feeding.type}
|
||||
if last_type == 'formula':
|
||||
last_feed_args['method'] = 'bottle'
|
||||
kwargs['initial'].update(last_feed_args)
|
||||
|
||||
# Remove custom kwargs so they do not interfere with `super` calls.
|
||||
for key in ['child', 'timer']:
|
||||
|
|
Loading…
Reference in New Issue