1
0
mirror of https://github.com/django/django.git synced 2025-10-25 22:56:12 +00:00

Fixed #8422: FilePathField now respects required=False.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10447 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss
2009-04-08 18:53:55 +00:00
parent 98ef7e85bd
commit a64a61bf4a
2 changed files with 21 additions and 1 deletions

View File

@@ -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):