Given these Django models:
class Job(models.Model):
pass
class Task(models.Model):
job = models.ForeignKey('Job', related_name='tasks')
status = models.CharField(choices=TaskStatus.CHOICES, max_length=30)
dependencies = models.ManyToManyField("self", related_name="dependents", symmetrical=False)
I want to query all Tasks with status PENDING and ALL dependencies having status COMPLETED for a single Job.
I wrote the following query, but it returns tasks that have at least one dependency with status completed, which is obviously not want I'm after.
tasks_that_can_be_executed = Task.objects.filter(
job__pk=job_id,
status=TaskStatus.PENDING,
dependencies__status=TaskStatus.COMPLETED
)
Any suggestions?
QI don't know it mostly use when we need to work with conditions? and filter always work withAND