Ticket #2266: RequiredIfOtherFieldsNotGiven.diff
File RequiredIfOtherFieldsNotGiven.diff, 1.1 KB (added by , 18 years ago) |
---|
-
django/core/validators.py
267 267 if not all_data.get(self.other, False) and not field_data: 268 268 raise ValidationError, self.error_message 269 269 270 class RequiredIfOtherFieldsNotGiven(object): 271 def __init__(self, other_field_names, error_message=gettext_lazy("Please enter something for at least one field.")): 272 self.other, self.error_message = other_field_names, error_message 273 self.always_test = True 274 275 def __call__(self, field_data, all_data): 276 one_field_given = False 277 for field in self.other: 278 if all_data.get(field, False): 279 one_field_given = True 280 break 281 if not one_field_given: 282 raise ValidationError, self.error_message 283 270 284 class RequiredIfOtherFieldsGiven(object): 271 285 def __init__(self, other_field_names, error_message=gettext_lazy("Please enter both fields or leave them both empty.")): 272 286 self.other, self.error_message = other_field_names, error_message