Home > Back-end >  AttributeError in Django Overlapping validation checking
AttributeError in Django Overlapping validation checking

Time:05-23

i am cretaing a validation rule in djano to check overlapping but i am getting this error, can you guys help me

there is two data field , when the data field will be overlapped than validation error will rise.

start_r= model.integerfield(blank=True, Null=True)
end_t=model.intergerfield(blank=True,Null=True)

form.py

class CheckForm(forms.ModelForm):
   def clean(self):
           start_r = cleaned_data.get("start_r",[])
           end_t =cleaned_data.get("end_t",[])
           if (start_r.end >= end_t.start) and (start_r.start <= end_t.end):
              raise ValidationError("Overlap not allowed.")

i am getting error this one 'NoneType' object has no attribute 'end'

CodePudding user response:

What do you mean with start_r.end or end_t.start? The error message says start_r is None, so there is no end attribute. But even if the start_r is not None, those fields are defined as an integer, not an object.

To access the cleaned_data, you need to use one of the 2 commands bellow:

  • cleaned_data = super(CheckForm, self).clean()
  • cleaned_data = self.cleaned_data

If you explain what you need in more detail, I could help better.

  • Related