Tidied code, added replace() method to FileField
This commit is contained in:
committed by
Florian Schlachter
parent
6bfd6c322b
commit
47bfeec115
@@ -24,8 +24,8 @@ class BaseField(object):
|
||||
_index_with_types = True
|
||||
|
||||
def __init__(self, db_field=None, name=None, required=False, default=None,
|
||||
unique=False, unique_with=None, primary_key=False, validation=None,
|
||||
choices=None):
|
||||
unique=False, unique_with=None, primary_key=False,
|
||||
validation=None, choices=None):
|
||||
self.db_field = (db_field or name) if not primary_key else '_id'
|
||||
if name:
|
||||
import warnings
|
||||
@@ -86,13 +86,15 @@ class BaseField(object):
|
||||
# check choices
|
||||
if self.choices is not None:
|
||||
if value not in self.choices:
|
||||
raise ValidationError("Value must be one of %s."%unicode(self.choices))
|
||||
raise ValidationError("Value must be one of %s."
|
||||
% unicode(self.choices))
|
||||
|
||||
# check validation argument
|
||||
if self.validation is not None:
|
||||
if callable(self.validation):
|
||||
if not self.validation(value):
|
||||
raise ValidationError('Value does not match custom validation method.')
|
||||
raise ValidationError('Value does not match custom' \
|
||||
'validation method.')
|
||||
else:
|
||||
raise ValueError('validation argument must be a callable.')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user