Changeset 9334
- Timestamp:
- 11/04/08 13:48:35 (8 months ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/forms/models.py (modified) (2 diffs)
- django/trunk/tests/modeltests/model_forms/models.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r9263 r9334 345 345 Vinay Sajip <vinay_sajip@yahoo.co.uk> 346 346 David Schein 347 Bernd Schlapsi 347 348 scott@staplefish.com 348 349 Ilya Semenov <semenov@inetss.com> django/trunk/django/forms/models.py
r9326 r9334 42 42 " validate." % (opts.object_name, fail_message)) 43 43 cleaned_data = form.cleaned_data 44 file_field_list = [] 44 45 for f in opts.fields: 45 46 if not f.editable or isinstance(f, models.AutoField) \ … … 50 51 if exclude and f.name in exclude: 51 52 continue 53 # Defer saving file-type fields until after the other fields, so a 54 # callable upload_to can use the values from other fields. 55 if isinstance(f, models.FileField): 56 file_field_list.append(f) 57 else: 58 f.save_form_data(instance, cleaned_data[f.name]) 59 60 for f in file_field_list: 52 61 f.save_form_data(instance, cleaned_data[f.name]) 62 53 63 # Wrap up the saving of m2m data as a function. 54 64 def save_m2m(): django/trunk/tests/modeltests/model_forms/models.py
r9288 r9334 100 100 101 101 class ImageFile(models.Model): 102 def custom_upload_path(self, filename): 103 path = self.path or 'tests' 104 return '%s/%s' % (path, filename) 105 102 106 description = models.CharField(max_length=20) 103 107 try: … … 107 111 # If PIL is not available, this test is equivalent to TextFile above. 108 112 from PIL import Image, _imaging 109 image = models.ImageField(storage=temp_storage, upload_to= 'tests')113 image = models.ImageField(storage=temp_storage, upload_to=custom_upload_path) 110 114 except ImportError: 111 image = models.FileField(storage=temp_storage, upload_to='tests') 115 image = models.FileField(storage=temp_storage, upload_to=custom_upload_path) 116 path = models.CharField(max_length=16, blank=True, default='') 112 117 113 118 def __unicode__(self): … … 1123 1128 >>> instance.delete() 1124 1129 1130 # Test callable upload_to behavior that's dependent on the value of another field in the model 1131 >>> f = ImageFileForm(data={'description': u'And a final one', 'path': 'foo'}, files={'image': SimpleUploadedFile('test4.png', image_data)}) 1132 >>> f.is_valid() 1133 True 1134 >>> instance = f.save() 1135 >>> instance.image 1136 <...FieldFile: foo/test4.png> 1137 >>> instance.delete() 1138 1125 1139 # Media on a ModelForm ######################################################## 1126 1140
