Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django-获取日期范围重叠的所有模型实例_Python_Django_Filter - Fatal编程技术网

Python django-获取日期范围重叠的所有模型实例

Python django-获取日期范围重叠的所有模型实例,python,django,filter,Python,Django,Filter,假设我有以下模型: class DateRange(models.Model): start = models.DateTimeField() end = models.DateTimeField() 是否有一种方法可以获取所有在start到end范围内有重叠的日期范围实例对?例如,如果我有: id | start | end -----+---------------------+--------------------- 1 | 20

假设我有以下模型:

class DateRange(models.Model):
    start = models.DateTimeField()
    end = models.DateTimeField()
是否有一种方法可以获取所有在
start
end
范围内有重叠的日期范围实例对?例如,如果我有:

  id |  start              |  end
-----+---------------------+---------------------
   1 | 2020-01-02 12:00:00 | 2020-01-02 16:00:00  # overlap with 2, 3 and 5
   2 | 2020-01-02 13:00:00 | 2020-01-02 14:00:00  # overlap with 1 and 3
   3 | 2020-01-02 13:30:00 | 2020-01-02 17:00:00  # overlap with 1 and 2
   4 | 2020-01-02 10:00:00 | 2020-01-02 10:30:00  # no overlap
   5 | 2020-01-02 12:00:00 | 2020-01-02 12:30:00  # overlap with 1
我想要:

 id_1 | id_2
------+-----
    1 |    2
    1 |    3
    1 |    5
    2 |    3
你有没有想过最好的方法?id_1和id_2的顺序并不重要,但我确实需要区分(例如-
id_1=1,id_2=2
id_1=2,id_2=1
相同,不应重复)