2

假设我有以下模型:

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共同的 s (最好使用 ORM 来取回Trial实例)?

4

0 回答 0