Tidied code, added replace() method to FileField

This commit is contained in:
Steve Challis
2010-06-03 15:27:21 +08:00
committed by Florian Schlachter
parent 6bfd6c322b
commit 47bfeec115
4 changed files with 40 additions and 11 deletions

View File

@@ -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.')