Fixed #1756 -- Permit selecting no file in a FilePathField with blank = True.

Thanks to Adam Endicott for the patch.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3146 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2006-06-19 12:30:43 +00:00
parent 1fc3b3229a
commit 271083cf7c
1 changed files with 2 additions and 1 deletions

View File

@ -898,10 +898,11 @@ class FilePathField(SelectField):
"A SelectField whose choices are the files in a given directory." "A SelectField whose choices are the files in a given directory."
def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=None): def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=None):
import os import os
from django.db.models import BLANK_CHOICE_DASH
if match is not None: if match is not None:
import re import re
match_re = re.compile(match) match_re = re.compile(match)
choices = [] choices = not is_required and BLANK_CHOICE_DASH[:] or []
if recursive: if recursive:
for root, dirs, files in os.walk(path): for root, dirs, files in os.walk(path):
for f in files: for f in files: