queries across relationships
I am new to Django and I am trying to implement this Relationship in Django
Person has a Car Car can be tested for problems A car should be tested for a select set of criterias
So I implement it as
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()
I am trying to import the fields of car into test. Is there anyway way to do it? I am trying to replicate this SQL statement
SELECT test FROM table WHERE OWNER IS x (object instance) AND CAR IS isDiesel
Thanks in advance.
Car.objects.filter(isDiesel=True, owner=person_instance)
This will return an array of Car
objects.
You should have a read at the Django docs on this subject; this framework has a really badass documentation.
链接地址: http://www.djcxy.com/p/38676.html上一篇: Django南迁移错误与postgresql数据库中的唯一字段
下一篇: 查询各种关系