Added a get_proxy_obj method to FileField and handle FileFields in container fields properly in ImageGridFsProxy.
This commit is contained in:
		| @@ -1190,9 +1190,7 @@ class FileField(BaseField): | ||||
|         # Check if a file already exists for this model | ||||
|         grid_file = instance._data.get(self.name) | ||||
|         if not isinstance(grid_file, self.proxy_class): | ||||
|             grid_file = self.proxy_class(key=self.name, instance=instance, | ||||
|                                          db_alias=self.db_alias, | ||||
|                                          collection_name=self.collection_name) | ||||
|             grid_file = self.get_proxy_obj(key=key, instance=instance) | ||||
|             instance._data[self.name] = grid_file | ||||
|  | ||||
|         if not grid_file.key: | ||||
| @@ -1214,15 +1212,23 @@ class FileField(BaseField): | ||||
|                     pass | ||||
|  | ||||
|             # Create a new proxy object as we don't already have one | ||||
|             instance._data[key] = self.proxy_class(key=key, instance=instance, | ||||
|                                                    db_alias=self.db_alias, | ||||
|                                                    collection_name=self.collection_name) | ||||
|             instance._data[key] = self.get_proxy_obj(key=key, instance=instance) | ||||
|             instance._data[key].put(value) | ||||
|         else: | ||||
|             instance._data[key] = value | ||||
|  | ||||
|         instance._mark_as_changed(key) | ||||
|          | ||||
|     def get_proxy_obj(self, key, instance, db_alias=None, collection_name=None): | ||||
|         if db_alias is None: | ||||
|             db_alias = self.db_alias | ||||
|         if collection_name is None: | ||||
|             collection_name = self.collection_name | ||||
|              | ||||
|         return  self.proxy_class(key=key, instance=instance, | ||||
|                                  db_alias=db_alias, | ||||
|                                  collection_name=collection_name) | ||||
|  | ||||
|     def to_mongo(self, value): | ||||
|         # Store the GridFS file id in MongoDB | ||||
|         if isinstance(value, self.proxy_class) and value.grid_id is not None: | ||||
| @@ -1255,6 +1261,11 @@ class ImageGridFsProxy(GridFSProxy): | ||||
|         applying field properties (size, thumbnail_size) | ||||
|         """ | ||||
|         field = self.instance._fields[self.key] | ||||
|         # if the field from the instance has an attribute field | ||||
|         # we use that one and hope for the best. Usually only container | ||||
|         # fields have a field attribute. | ||||
|         if hasattr(field, 'field'): | ||||
|             field = field.field | ||||
|  | ||||
|         try: | ||||
|             img = Image.open(file_obj) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user