Ticket #10121: 10121.diff
File 10121.diff, 1.5 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/files.py
213 213 def generate_filename(self, instance, filename): 214 214 return os.path.join(self.get_directory_name(), self.get_filename(filename)) 215 215 216 def save_form_data(self, instance, data): 217 if data and isinstance(data, UploadedFile): 218 getattr(instance, self.name).save(data.name, data, save=False) 219 216 220 def formfield(self, **kwargs): 217 221 defaults = {'form_class': forms.FileField} 218 222 # If a file has been provided previously, then the form doesn't require -
tests/modeltests/model_forms/models.py
1030 1030 >>> instance.file 1031 1031 <FieldFile: tests/test3.txt> 1032 1032 1033 # Instance can be edited w/out re-uploading the file and existing file should be preserved. 1034 1035 >>> f = TextFileForm(data={'description': u'New Description'}, instance=instance) 1036 >>> f.fields['file'].required = False 1037 >>> f.is_valid() 1038 True 1039 >>> instance = f.save() 1040 >>> instance.description 1041 u'New Description' 1042 >>> instance.file 1043 <FieldFile: tests/test3.txt> 1044 1033 1045 # Delete the current file since this is not done by Django. 1034 1046 >>> instance.file.delete() 1035 1047 >>> instance.delete()