borntonetwork wrote:
I have a model object called Customer. It contains the typical attributes/fields you might expect (name, street, apt, city, state, etc). Among these fields are 3 called home_phone, work_phone, and cell_phone. In the admin web interface, I need to ensure that the user must enter data into at least one of the 3 fields -- doesn't matter which one.
Hi, I think the solution that would require minimal hacking is to attach a custom validator to your phone fields via the validator_list attribute: class RequiredIfNoneGiven(object): def __init__(self, other_field_names, error_message=gettext_lazy("Please enter something for at least one field.")): self.others, self.error_message = other_field_names, error_message self.always_test = True def __call__(self, field_data, all_data): other_values = [all_data.get(other) for other in self.others] other_values = [value for value in other_values if value] if not other_values and not field_data: raise ValidationError, self.error_message class Customer(models.Model) ... home_phone = models.YourField(..., validator_list=[RequiredIfNoneGiven(['work_phone', 'cell_phone'])]) work_phone = models.YourField(..., validator_list=[RequiredIfNoneGiven(['home_phone', 'cell_phone'])]) cell_phone = models.YourField(..., validator_list=[RequiredIfNoneGiven(['home_phone', 'work_phone'])]) So I *think* that will make it look nice when someone violates this rule in the admin interface. You can change the validation semantics in the __call__ method. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---