Ticket #14531: validate_unique.patch
File validate_unique.patch, 1.8 KB (added by , 14 years ago) |
---|
-
django/forms/models.py
202 202 self.fields = getattr(options, 'fields', None) 203 203 self.exclude = getattr(options, 'exclude', None) 204 204 self.widgets = getattr(options, 'widgets', None) 205 self.validate_unique = getattr(options, 'validate_unique', None) # change to True when deprecation ends 205 206 206 207 207 208 class ModelFormMetaclass(type): … … 262 263 # if initial was provided, it should override the values from instance 263 264 if initial is not None: 264 265 object_data.update(initial) 265 # self._validate_unique will be set to True by BaseModelForm.clean().266 # It is False by default so overriding self.clean() and failing to call267 # super will stop validate_unique from being called.268 self._validate_unique = False269 266 super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data, 270 267 error_class, label_suffix, empty_permitted) 271 268 … … 323 320 return exclude 324 321 325 322 def clean(self): 326 self._validate_unique = True 323 opts = self._meta 324 if opts.validate_unique is None: 325 opts.validate_unique = True 327 326 return self.cleaned_data 328 327 329 328 def _post_clean(self): … … 357 356 self._update_errors({NON_FIELD_ERRORS: e.messages}) 358 357 359 358 # Validate uniqueness if needed. 360 if self._validate_unique:359 if opts.validate_unique: 361 360 self.validate_unique() 361 elif opts.validate_unique is None: 362 raise PendingDeprecationWarning('?') 362 363 363 364 def validate_unique(self): 364 365 """