Home > Back-end >  Postive and Negative Validation Check is Not Working In Django Forms
Postive and Negative Validation Check is Not Working In Django Forms

Time:06-19

I am working this validation check in django , i have to check postiva values. I have values a,b,c,d if (a,b) also (c,d) positive value will not allowed, i wrote the code this way but do not know why is not checking the validation.

I am working on django forms.py

for i in range(count):
        a = int(self.data.get(f'runtime_set-{i}-a') or 0)
        b = int(self.data.get(f'runtime_set-{i}-b') or 0)
        c = int(self.data.get(f'runtime_set-{i}-c') or 0)
        d = int(self.data.get(f'runtime_set-{i}-d') or 0)
        if a ==b==c==d==0:
            continue
        if (a   b) > 0 and (c   d) > 0:
            raise ValidationError(
                "When A  '{a}' , B '{b}'  is postive then  C '{c}' and d'{d}' positive    value is not allowed  ")

CodePudding user response:

As mentioned in the comment that I made the problem was that you have the following boolean expresion:

if (a   b) > 0    (c   d) > 0:

So change to this to solve the problem:

if (a   b) > 0 and  (c   d) > 0:
  • Related