'Check Overlapping intervals integerfield validation django python

can anyone help me how to solve overlapping validation in django

moldel.py

 start = IntegerRangeField()
 end = IntegerRangeField()

form.py

class CheckForm(forms.ModelForm): def clean(self):

start=cleaned_data.get("start")
    end = cleaned_data.get("end")
    conflicts = Check.objects.filter(
        start_bbch__lte=end,
        end_end__gte=start,
    )
    if any(conflicts):
        raise forms.ValidationError(_("overlapping not allowed" % conflicts.count()))
    return cleaned_data


Solution 1:[1]

I think to check for overlapping you need to make sure that neither the start nor the end of your new object is within an existing interval.

So I would suggest something like this:

conflicts = Check.objects.filter(
    start_bbch__gte=start, end_end__lte=start
) | Check.objects.filter(
    start_bbch__gte=end, end_end__lte=end
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Erik Kalkoken