class Service(models.Model):
invoice = models.Charfield()
class Sparepart(models.Model):
name = models.Charfield()
service = models.Foreignkey(Service)
class SparepartDetail(models.Model):
type = models.Charfield()
qty = models.IntegerField()
sparepart = models.Foreignkey(Sparepart)
Как сделать так, чтобы запрос соединялся так:
FROM service
LEFT OUTER JOIN sparepart ON (
service.id = sparepart.service_id
)
LEFT OUTER JOIN sparepartdetail ON (
sparepart.id = sparepartdetail.sparepart_id AND sparepartdetail.type = 'USED'
)