diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
index f9bfc9d..a459fbf 100644
a
|
b
|
class FieldFile(File):
|
20 | 20 | self.instance = instance |
21 | 21 | self.field = field |
22 | 22 | self.storage = field.storage |
23 | | self._name = name or u'' |
| 23 | self._name = name |
24 | 24 | self._closed = False |
25 | 25 | self._committed = True |
26 | 26 | |
… |
… |
class FileField(Field):
|
175 | 175 | def get_db_prep_value(self, value): |
176 | 176 | "Returns field's value prepared for saving into a database." |
177 | 177 | # Need to convert File objects provided via a form to unicode for database insertion |
178 | | if value is None: |
| 178 | if value is None or (hasattr(value, 'name') and value.name is None and self.null): |
179 | 179 | return None |
180 | 180 | return unicode(value) |
181 | 181 | |
diff --git a/tests/modeltests/files/models.py b/tests/modeltests/files/models.py
index 741a284..2e03e3c 100644
a
|
b
|
class Storage(models.Model):
|
31 | 31 | |
32 | 32 | normal = models.FileField(storage=temp_storage, upload_to='tests') |
33 | 33 | custom = models.FileField(storage=temp_storage, upload_to=custom_upload_to) |
34 | | random = models.FileField(storage=temp_storage, upload_to=random_upload_to) |
| 34 | random = models.FileField(storage=temp_storage, upload_to=random_upload_to, null=True) |
35 | 35 | default = models.FileField(storage=temp_storage, upload_to='tests', default='tests/default.txt') |
36 | 36 | |
37 | 37 | __test__ = {'API_TESTS':""" |
… |
… |
ValueError: The 'normal' attribute has no file associated with it.
|
127 | 127 | >>> obj4.random.save('random_file', ContentFile('random content')) |
128 | 128 | >>> obj4.random |
129 | 129 | <FieldFile: .../random_file> |
| 130 | >>> obj4.random = None |
| 131 | >>> obj4.save() |
| 132 | >>> obj4.random |
| 133 | <FieldFile: None> |
| 134 | >>> Storage.objects.values_list('random', flat=True).filter(pk=obj4.pk) |
| 135 | [None] |
130 | 136 | |
131 | 137 | # Clean up the temporary files and dir. |
132 | 138 | >>> obj1.normal.delete() |