0

I have contact model

class Contact(models.Model):
    company = models.CharField(max_length=200, blank=True)
    vatkey = models.CharField(max_length=200, blank=True)

Can i set reference that : when company name is not empty then vatkey is required ?

regards

Dominik
  • 99
  • 1
  • 11

1 Answers1

1

Use Django Validatiors.

from django.core.exceptions import ValidationError

class Contact(models.Model):

     ...
     def clean(self):
         if self.company and not self.vatkey:
            raise ValidationError('Vatkey is required')
Sagar
  • 1,115
  • 2
  • 11
  • 23