Skip to content

How to pass initial values to FilterForm #60

@jphuart

Description

@jphuart

I've tried three different strategies, none works:

  1. in the field definition:
    date_from = 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions