diff options
| author | TildaDares <mathildaudufo@gmail.com> | 2026-03-29 22:02:10 +0100 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-04-29 14:52:25 -0400 |
| commit | 3f912ee4189602b4df121c0dc0428673fda5c253 (patch) | |
| tree | f696c3609f6de8520932a662c88f4918b5fba7fb /django/forms/fields.py | |
| parent | 60a9c70496e5d7b971928ce3da5b47c8836a4def (diff) | |
Fixed #16429 -- Extracted set_choices() method from FilePathField.__init__().
Diffstat (limited to 'django/forms/fields.py')
| -rw-r--r-- | django/forms/fields.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index 26640ed7d3..ab3f6876df 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -1197,7 +1197,9 @@ class FilePathField(ChoiceField): self.path, self.match, self.recursive = path, match, recursive self.allow_files, self.allow_folders = allow_files, allow_folders super().__init__(choices=(), **kwargs) + self.set_choices() + def set_choices(self): if self.required: self.choices = [] else: @@ -1206,20 +1208,20 @@ class FilePathField(ChoiceField): if self.match is not None: self.match_re = re.compile(self.match) - if recursive: + if self.recursive: for root, dirs, files in sorted(os.walk(self.path)): if self.allow_files: for f in sorted(files): if self.match is None or self.match_re.search(f): f = os.path.join(root, f) - self.choices.append((f, f.replace(path, "", 1))) + self.choices.append((f, f.replace(self.path, "", 1))) if self.allow_folders: for f in sorted(dirs): if f == "__pycache__": continue if self.match is None or self.match_re.search(f): f = os.path.join(root, f) - self.choices.append((f, f.replace(path, "", 1))) + self.choices.append((f, f.replace(self.path, "", 1))) else: choices = [] with os.scandir(self.path) as entries: |
