Fixed BinaryField python value issue (MongoEngine/mongoengine#48)

This commit is contained in:
Ross Lawley
2012-08-01 14:57:46 +01:00
parent 2c69d8f0b0
commit a43d0d4612
3 changed files with 18 additions and 7 deletions

View File

@@ -845,12 +845,9 @@ class BinaryField(BaseField):
def to_mongo(self, value):
return Binary(value)
def to_python(self, value):
return "%s" % value
def validate(self, value):
if not isinstance(value, basestring):
self.error('BinaryField only accepts string values')
if not isinstance(value, (basestring, Binary)):
self.error('BinaryField only accepts string or bson Binary values')
if self.max_bytes is not None and len(value) > self.max_bytes:
self.error('Binary value is too long')