FileField's values are now optional. When no value is applied, no File object is created and referenced.

This commit is contained in:
Florian Schlachter
2010-07-20 22:46:00 +02:00
parent 03c0fd9ada
commit aa00feb6a5
2 changed files with 11 additions and 6 deletions

View File

@@ -591,15 +591,20 @@ class FileField(BaseField):
def to_mongo(self, value):
# Store the GridFS file id in MongoDB
return self.gridfs.grid_id
if self.gridfs.grid_id is not None:
return self.gridfs.grid_id
return None
def to_python(self, value):
# Use stored value (id) to lookup file in GridFS
return self.gridfs.get(id=value)
if self.gridfs.grid_id is not None:
return self.gridfs.get(id=value)
return None
def validate(self, value):
assert isinstance(value, GridFSProxy)
assert isinstance(value.grid_id, pymongo.objectid.ObjectId)
if value.grid_id is not None:
assert isinstance(value, GridFSProxy)
assert isinstance(value.grid_id, pymongo.objectid.ObjectId)
class GeoPointField(BaseField):
"""A list storing a latitude and longitude.