The following query:
SELECT L1.task_id FROM task_log L1
LEFT JOIN task_log L2 ON L1.started BETWEEN L2.started AND L2.ended
WHERE L2.task_id IS NULL;
Simply reads all task logs that were started when no other tasks were running. An abstraction in PHP/ZF2 looks like this:
$db->select(array('L1' => 'task_log'))
->columns('task_id')
->join(array('L2' => 'task_log'), "L1.started BETWEEN L2.started AND L2.ended", array(), 'left');
I was looking for something similar in Django, or at least python. As per this discussion, it is (understandably) out of question to build this in django models. Are there any other alternatives in python/django?