After discussing with Honza, we agreed that the dichotomy between forms and models that was present before will remain, i.e. instance will always be a model instance if given and all_values will always be form.cleaned_data.
Honza's rationale was that it's common to have properties in models and therefore model_instance.__dict__ (or forms.models.model_to_dict) may be too constraining. Thus, a generic value getter will be used in validators to provide uniform access to dict values and instance fields as follows: def _get_value(name, instance, all_values): if instance is not None and hasattr(instance, name): return getattr(instance, name) if name in all_values: return all_values[name] raise AttributeError('%s not found in forms values or model instance') class RequiredIfOtherFieldEquals(object): def __call__(self, value, all_values={}, instance=None): if _get_value(self.other_field, instance, all_values) == self.other_value and not value: raise ValidationError(self.error_message, REQUIRED) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---