You do this in the validation: http://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other
-leond On Sep 21, 11:34 pm, lance <lan...@gmail.com> wrote: > Newbie question... > > In defining my model, I have two CharFields of a given class. The > business logic requires that one or both of the fields be filled in. > Either of the fields can be blank as long as the other one isn't. > > Is there a Django best practice way to solve this? Should this be > handled in the Model or down stream in the View or...? > > I was thinking something along these lines would be useful... > > one = models.CharField(max_length=50, optional_blank='two') > two = models.CharField(max_length=50, optional_blank='one') > > such that the "one" field can be optionally left blank if the two > field is not blank and vice-versa. > > Additionally, the functionality could be extended out to include: > > three = models.CharField(max_length=50, optional_blank=('one', two',)) > > such that the "three" field can be optionally left blank if both the > one and two fields are not blank. > > Or should all of the fields be set to blank=True and the field > requirements are handled downstream in the View? --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---