This commit is contained in:
Ross Lawley
2012-04-25 12:40:53 +01:00
2 changed files with 24 additions and 4 deletions

View File

@@ -875,10 +875,14 @@ class GridFSProxy(object):
self.newfile.writelines(lines)
def read(self, size=-1):
try:
return self.get().read(size)
except:
gridout = self.get()
if gridout is None:
return None
else:
try:
return gridout.read(size)
except:
return ""
def delete(self):
# Delete file from GridFS, FileField still remains
@@ -935,7 +939,7 @@ class FileField(BaseField):
def __set__(self, instance, value):
key = self.name
if isinstance(value, file) or isinstance(value, str):
if (hasattr(value, 'read') and not isinstance(value, GridFSProxy)) or isinstance(value, str):
# using "FileField() = file/string" notation
grid_file = instance._data.get(self.name)
# If a file already exists, delete it