I've tried three different strategies, none works:
1) in the field definition:
datefrom = DateTimeField(label=('Date from'),
initial='{:%Y-%m-%d}'.format(datetime.date.today()),
required=True
)
2) In the form init:
def init(self, *args, *kwargs):
updated_initial = {}
updated_initial['date_from'] = '{:%Y-%m-%d}'.format(datetime.date.today())
kwargs.update(initial=updated_initial)
super().init(args, **kwargs)
3) In the get_initial of the BrowseView that uses this form:
def get_initial(self):
initial = super().get_initial()
initial['date_from'] = '{:%Y-%m-%d}'.format(datetime.date.today())
return initial
None of them works. Any ideas on how to populate the FilterForm of the BrowseView with initial values?
I've tried three different strategies, none works:
1) in the field definition: datefrom = DateTimeField(label=('Date from'), initial='{:%Y-%m-%d}'.format(datetime.date.today()), required=True )
2) In the form init: def init(self, *args, *kwargs): updated_initial = {} updated_initial['date_from'] = '{:%Y-%m-%d}'.format(datetime.date.today()) kwargs.update(initial=updated_initial) super().init(args, **kwargs)
3) In the get_initial of the BrowseView that uses this form: def get_initial(self): initial = super().get_initial() initial['date_from'] = '{:%Y-%m-%d}'.format(datetime.date.today()) return initial
None of them works. Any ideas on how to populate the FilterForm of the BrowseView with initial values?