mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #6302. FileField no longer requires a value if one already exists. Thanks Brian Rosner and Øyvind Saltvik.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7021 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -797,13 +797,17 @@ class FileField(Field):
|
||||
return os.path.normpath(f)
|
||||
|
||||
def save_form_data(self, instance, data):
|
||||
if data:
|
||||
from django.newforms.fields import UploadedFile
|
||||
if data and isinstance(data, UploadedFile):
|
||||
getattr(instance, "save_%s_file" % self.name)(data.filename, data.content, save=False)
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'form_class': forms.FileField}
|
||||
# If a file has been provided previously, then the form doesn't require
|
||||
# that a new file is provided this time.
|
||||
# The code to mark the form field as not required is used by
|
||||
# form_for_instance, but can probably be removed once form_for_instance
|
||||
# is gone. ModelForm uses a different method to check for an existing file.
|
||||
if 'initial' in kwargs:
|
||||
defaults['required'] = False
|
||||
defaults.update(kwargs)
|
||||
|
||||
Reference in New Issue
Block a user