Situation
I have 3 models. Model A, model B and model C.
class A(Model):
B_id = ForeignKey(B)
id = IntegerField()
pub_date = DateField()
class B(Model):
id = IntegerField(primary_key = True)
class C(Model):
B_id = ForeignKey(B)
pub_date = DateField()
information = TextField()
Model A and model C both have a field called B_id, which is a foreign key to model B. So there is no direct connection from B to A or C.
Goal
I'm given an ID from model A. Now I need all informations from C where the pub_date matches the pub_date in A and the B_id matches the B_id in A.
In SQL, this would be a pretty easy query:
SELECT C.information FROM A JOIN C USING(B_id, pub_date) WHERE A.id = 1234;
But I simply can't figure out how to do this in Django ORM syntax, as a filter()-clause only works if there is a direct connection path from C to A.
--
Edit: Please note that there is more than one row in A that matches one id.