fusionbox / django-betterforms

Making forms suck less
https://django-betterforms.readthedocs.org/
BSD 2-Clause "Simplified" License
135 stars 54 forks source link

How to pass initial values to FilterForm #60

Open jphuart opened 4 years ago

jphuart commented 4 years ago

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?