假设我有以下型号:
from django.db import models
class Experiment(models.Model):
creation_timestamp = models.DateTimeField(auto_now_add=True)
class Alien(models.Model):
experiment = models.ForeignKey(Experiment)
class Trial(models.Model):
experiment = models.ForeignKey(Experiment)
dosage = models.PositiveIntegerField()
class TrialGroup(models.Model):
trial = models.ForeignKey(Trial, related_name='groups')
aliens = models.ManyToManyField(Alien)
positive_outcome = models.BooleanField()
给定一个Trial
实例,如何创建一个查询来识别同一个Experiment
中具有一个或多个Alien
个共同点的所有其他试验(最好使用ORM获取)返回Trial
个实例)?