On Thu, 2006-05-18 at 04:51 +0000, qhfgva wrote: > Class Foo(Model): > blah = CharField(maxlength=20) > bar = ForeignKey(Qwerty) # requred field > baz = CharField(maxlength=20, null=False) > > In the above class I'd like to make baz a required field if bar is of a > certain value otherwise it can be blank. If there a way to accomplish > this?
This is fairly simple. You add an extra validator to each of the fields you care about and then write a validator that does the checking you want. The validators will receive the value for the field in question and a dictionary of all the values for all the fields. So a validator for baz can easily check that the new value is constrained by the value for bar. More concretely, have a look at the validator_list parameter in the models documentation http://www.djangoproject.com/documentation/model_api/#validator-list and then the validator documentation (which is linked from the above section as well, so it's fairly self-explanatory): http://www.djangoproject.com/documentation/forms/#validators Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---