@@ -275,6 +275,28 @@ def to_python(self, value, **kwargs):
275
275
raise self .exception ("Array {0} cannot be converted to int" .format (value ))
276
276
277
277
278
+ # FieldFile also needs a model instance to save changes.
279
+ class FakeInstance (object ):
280
+ """
281
+ FieldFile needs a model instance to update when file is persisted
282
+ or deleted
283
+ """
284
+
285
+ def save (self ):
286
+ return
287
+
288
+
289
+ class FakeField (object ):
290
+ """
291
+ FieldFile needs a field object to generate a filename, persist
292
+ and delete files, so we are effectively mocking that.
293
+ """
294
+
295
+ name = "noop"
296
+ attname = "noop"
297
+ max_length = 10000
298
+
299
+
278
300
class PreferenceFieldFile (FieldFile ):
279
301
"""
280
302
In order to have the same API that we have with models.FileField,
@@ -285,33 +307,9 @@ class PreferenceFieldFile(FieldFile):
285
307
286
308
def __init__ (self , preference , storage , name ):
287
309
super (FieldFile , self ).__init__ (None , name )
288
-
289
- # FieldFile also needs a model instance to save changes.
290
- class FakeInstance (object ):
291
- """
292
- FieldFile needs a model instance to update when file is persisted
293
- or deleted
294
- """
295
-
296
- def save (self ):
297
- return
298
-
299
310
self .instance = FakeInstance ()
300
-
301
- class FakeField (object ):
302
- """
303
- FieldFile needs a field object to generate a filename, persist
304
- and delete files, so we are effectively mocking that.
305
- """
306
-
307
- name = "noop"
308
- attname = "noop"
309
- max_length = 10000
310
-
311
- def generate_filename (field , instance , name ):
312
- return os .path .join (self .preference .get_upload_path (), f .name )
313
-
314
311
self .field = FakeField ()
312
+ self .field .storage = storage
315
313
self .storage = storage
316
314
self ._committed = True
317
315
self .preference = preference
@@ -483,5 +481,5 @@ def to_python(cls, value, **kwargs):
483
481
while "" in ret :
484
482
pos = ret .index ("" )
485
483
val = ret [pos - 1 ] + cls .separator + ret [pos + 1 ]
486
- ret = ret [0 : pos - 1 ] + [val ] + ret [pos + 2 :]
484
+ ret = ret [0 : pos - 1 ] + [val ] + ret [pos + 2 :]
487
485
return ret
0 commit comments