Django - queries across relationships
我对姜戈不熟悉,我正努力在姜戈实现这种关系。
Person has a Car
Car can be tested for problems
A car should be tested for a select set of criterias号
所以我把它实现为
1
2
3
4
5
6
7
8 class Person(model.Model):
name = models.CharField(max_length=60)
license = models.CharField(max_length=80)
class Car(models.Model):
name = models.CharField()
owner = models.ForeignKey('Person')
isDiesel = models.BooleanField()我正在尝试将汽车的各个领域导入到测试中。有什么办法吗?我正在尝试复制此SQL语句
1 SELECT test FROM table WHERE OWNER IS x (object instance) AND CAR IS isDiesel号
事先谢谢。
1 Car.objects.filter(isDiesel=True, owner=person_instance)这将返回一个
Car 对象数组。您应该在Django文档中阅读这个主题;这个框架有一个非常糟糕的文档。