Allow FileField to specify defaults directly on class

This commit is contained in:
Damien Nozay 2015-01-04 12:33:08 -08:00
parent 29f494f447
commit 8471a4a2f7

View File

@ -1084,11 +1084,14 @@ class FileField(Field):
'empty': _("The submitted file is empty."), 'empty': _("The submitted file is empty."),
'max_length': _('Ensure this filename has at most {max_length} characters (it has {length}).'), 'max_length': _('Ensure this filename has at most {max_length} characters (it has {length}).'),
} }
# allows subclasses to change defaults
use_url = api_settings.UPLOADED_FILES_USE_URL use_url = api_settings.UPLOADED_FILES_USE_URL
max_length = None
allow_empty_file = False
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.max_length = kwargs.pop('max_length', None) self.max_length = kwargs.pop('max_length', self.max_length)
self.allow_empty_file = kwargs.pop('allow_empty_file', False) self.allow_empty_file = kwargs.pop('allow_empty_file', self.allow_empty_file)
self.use_url = kwargs.pop('use_url', self.use_url) self.use_url = kwargs.pop('use_url', self.use_url)
super(FileField, self).__init__(*args, **kwargs) super(FileField, self).__init__(*args, **kwargs)