Ticket #13184: forms_models.diff
File forms_models.diff, 1.8 KB (added by , 15 years ago) |
---|
-
django/forms/models.py
39 39 opts = instance._meta 40 40 41 41 cleaned_data = form.cleaned_data 42 errors = {} 42 43 file_field_list = [] 43 44 for f in opts.fields: 44 45 if not f.editable or isinstance(f, models.AutoField) \ … … 53 54 if isinstance(f, models.FileField): 54 55 file_field_list.append(f) 55 56 else: 56 f.save_form_data(instance, cleaned_data[f.name]) 57 try: 58 f.save_form_data(instance, cleaned_data[f.name]) 59 except ValidationError, e: 60 errors[f.name] = e.messages 57 61 58 62 for f in file_field_list: 59 f.save_form_data(instance, cleaned_data[f.name]) 63 try: 64 f.save_form_data(instance, cleaned_data[f.name]) 65 except ValidationError, e: 66 errors[f.name] = e.messages 67 68 if errors: 69 raise ValidationError(errors) 60 70 61 71 return instance 62 72 … … 320 330 opts = self._meta 321 331 322 332 # Update the model instance with self.cleaned_data. 323 self.instance = construct_instance(self, self.instance, opts.fields, opts.exclude) 333 to_python_errors = [] 334 try: 335 self.instance = construct_instance(self, self.instance, opts.fields, opts.exclude) 336 except ValidationError, e: 337 to_python_errors = e.message_dict.keys() 338 self._update_errors(e.message_dict) 324 339 325 340 # Clean the model instance's fields. 326 341 try: 327 self.instance.clean_fields(exclude=exclude )342 self.instance.clean_fields(exclude=exclude+to_python_errors) 328 343 except ValidationError, e: 329 344 self._update_errors(e.message_dict) 330 345