summaryrefslogtreecommitdiff
path: root/django/forms/fields.py
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-04-08 18:53:55 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-04-08 18:53:55 +0000
commita64a61bf4a21f942828add0b7964f18cf777a5bb (patch)
tree8d1261875cdbeb29534b505a65fc8897a272a81b /django/forms/fields.py
parent98ef7e85bdaad4b21c31b425a62b2c8bc294be48 (diff)
Fixed #8422: FilePathField now respects required=False.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10447 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms/fields.py')
-rw-r--r--django/forms/fields.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 9c4084450a..bd4f3d4a80 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -829,9 +829,15 @@ class FilePathField(ChoiceField):
super(FilePathField, self).__init__(choices=(), required=required,
widget=widget, label=label, initial=initial, help_text=help_text,
*args, **kwargs)
- self.choices = []
+
+ if self.required:
+ self.choices = []
+ else:
+ self.choices = [("", "---------")]
+
if self.match is not None:
self.match_re = re.compile(self.match)
+
if recursive:
for root, dirs, files in os.walk(self.path):
for f in files:
@@ -846,6 +852,7 @@ class FilePathField(ChoiceField):
self.choices.append((full_file, f))
except OSError:
pass
+
self.widget.choices = self.choices
class SplitDateTimeField(MultiValueField):