diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/forms/fields.txt | 20 | ||||
| -rw-r--r-- | docs/releases/6.1.txt | 6 |
2 files changed, 26 insertions, 0 deletions
diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt index 085b36a0e5..8ddc5b9d79 100644 --- a/docs/ref/forms/fields.txt +++ b/docs/ref/forms/fields.txt @@ -724,6 +724,26 @@ For each field, we describe the default widget used if you don't specify whether folders in the specified location should be included. Either this or :attr:`allow_files` must be ``True``. + ``FilePathField`` has the following method: + + .. method:: set_choices() + + .. versionadded:: 6.1 + + Scans the directory at :attr:`path` and refreshes the field's + choices. This is called automatically during ``__init__()``, but it can + also be called explicitly to pick up files added to the directory + after the field was first instantiated (usually at server startup). For + example, call it in a form's ``__init__()`` to get fresh choices per + request:: + + class MyForm(forms.Form): + my_file = forms.FilePathField(path="/path/to/dir") + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["my_file"].set_choices() + ``FloatField`` -------------- diff --git a/docs/releases/6.1.txt b/docs/releases/6.1.txt index b4b4e60082..3da0c6546f 100644 --- a/docs/releases/6.1.txt +++ b/docs/releases/6.1.txt @@ -258,6 +258,12 @@ Forms :setting:`USE_BLANK_CHOICE_DASH` allows you to revert back to the old default label. +* :class:`~django.forms.FilePathField` now provides a + :meth:`~django.forms.FilePathField.set_choices` method to scan the + directory at :attr:`~django.forms.FilePathField.path` and refresh the + field's choices. This allows per-request refreshing when called in a form's + ``__init__()``. + Generic Views ~~~~~~~~~~~~~ |
