I am trying to join four tables where the three tables carry the primary key of the fourth table and this is my model.
class patient(models.Model):
choix = (
(0, 0),
(1, 1),
(0.1, 0.1),
(0.15, 0.15),
(0.2, 0.2),
(0.25, 0.25),
(0.3, 0.3),
(0.4, 0.4),
(0.5, 0.5),
(0.6, 0.6),
(0.7, 0.7),
(0.8, 0.8),
(0.9, 0.9),
)
date_creation=models.DateField(auto_now_add=True,null=True)
Nom_patient=models.CharField(max_length=200,null=True)
date_naissance=models.DateField(max_length=200,null=True)
numero_telephone=models.CharField(max_length=30, null=True)
adresse=models.CharField(max_length=100, null=True)
matricule=models.CharField(max_length=200,default=âPas de matriculeâ,null=True)
assurance=models.CharField(max_length=200,default=âNon assurĂ©â,null=True)
compagnie=models.CharField(max_length=200,default=âPas de compagnieâ,null=True)
medecin=models.CharField(max_length=200,null=True)
pourcentage = models.FloatField(max_length=20,default=âPas de pourcentageâ,null=True, choices=choix)
def str(self):
return self.Nom_patient
``
the second lab model
class labo(models.Model):
examen = (
(âAc anti- HAV IgM B 70â, âAc anti- HAV IgM B 70â),
(âAc anti- HBc IgM B 70â, âAc anti- HBc IgM B 70â),
(âAc anti- HBe B 70â, âAc anti- HBe B 70â),
(âAc anti- HBs (Test qualitatif ) B 70â, âAc anti- HBs (Test qualitatif ) B 70â),
(âAc anti- HVs (Titrage) B 100â, âAc anti- HVC (Titrage) B 100â),
(âAc anti- HVC (HĂ©pathie C) B 70â, âAc anti- HVC (HĂ©pathie C) B 70â),
(âAg HBe B 70â, âAg HBe 70â),
(âAg HBs B 70â, âAg HBs B 70â),
(âAntistreptolysine O ( ASLO) B 35â, âAntistreptolysine O (ASLO) B 35â),
(âSĂ©rodiagnostic de Widal et FĂ©lix B 40â, âSĂ©rodiagnostic de Widal et FĂ©lix B 40â),
("SĂ©rologie Amibienne B 60 ", âSĂ©rologie Amibienne B 60â),
(âSĂ©rologie bilharzienne B 60â, âSĂ©rologie bilharzienne B 60â),
(âSĂ©rologie palustre B 60â, âSĂ©rologie palustre B 60â),
("SĂ©rologie de la syphilis ( TPHA - VDRL) B 40 ", "SĂ©rologie de la syphilis ( TPHA - VDRL) B 40 "),
("SĂ©rologie des Chlamydia B 160 ", âSĂ©rologie des Chlamydia B 160â),
("SĂ©rologie des mycoplasmes B 100 ", "SĂ©rologie des mycoplasmes B 100 "),
(âSĂ©rologie de la rubĂ©ole (IgG - IgM) B 120â, âSĂ©rologie de la rubĂ©ole (IgG - IgM) B 120â),
(âSĂ©rologie de la toxoplasmose (IgG - IgM) B 80â, âSĂ©rologie de la toxoplasmose (IgG - IgM) B 80â),
(âSĂ©rologie CytomĂ©galovirus CMV B 160â, âSĂ©rologie CytomĂ©galovirus CMV B 160â),
("Sérologie herpétique (HSV 1 et HSV 2 ) B 160 ", "Sérologie herpétique (HSV 1 et HSV 2 ) B 160 "),
(âIgE totales B 150â, âIgE totales B 150â),
(âFacteur rhumatoĂŻdes B 50â, âFacteur rhumatoĂŻdes B 50â),
(âPrĂ©lĂšvementâ, âPrĂ©lĂšvementâ),
)
prix = (
(0, 0),
(100, 100),
(200, 200),
(250, 250),
(280, 280),
(300, 300),
(350, 350),
(400, 400),
(450, 450),
(2500, 2500),
)
date_labo=models.DateField(auto_now_add=True,null=True)
libelle_labo=models.CharField(max_length=1000,null=True,choices=examen)
activite_labo=models.CharField(max_length=1000,default=âNonâ,null=True)
cotation=models.FloatField(null=True)
prix=models.FloatField(null=True,choices=prix)
patient=models.ForeignKey(patient, null=True, on_delete=models.SET_NULL)
def str(self):
return self.libelle_labo
the third model specialist
class specialite(models.Model):
libel = (
(âNonâ, âNonâ),
(âCs Pedâ, âCs Pedâ),
(âCs Gynâ, âCs Gynâ),
(âEcho Pelvâ, âEcho Pelvâ),
(âCs + Echo Pelvâ, âCs + Echo Pelvâ),
(âEcho Obstâ, âEcho Obstâ),
(âCs+ Echo Obstâ, âCs+ Echo Obstâ),
(âCs Obstâ, âCs Obstâ),
(âEcho Morphâ, âecho morphoâ),
(âEcho Mamâ, âEcho Mamâ),
(âEcho Monitoâ, âEcho Monitoâ),
(âEcho Abdomâ, âEcho Abdomâ),
)
date_specialite = models.DateField(auto_now_add=True,null=True)
libelle_specialiste = models.CharField(max_length=200, null=True, choices=libel)
activite_specialite=models.CharField(max_length=1000,default=âNonâ,null=True)
prix_specialite=models.FloatField(null=True)
patient=models.ForeignKey(patient, null=True, on_delete=models.SET_NULL)
def str(self):
return self.libelle_specialiste
the fourth generalister model
class generalister(models.Model):
date_generaliste = models.DateTimeField(auto_now_add=True, null=True)
libelle_generaliste = models.CharField(max_length=200,null=True)
prix_generaliste = models.FloatField(null=True)
patient = models.ForeignKey(patient, null=True, on_delete=models.SET_NULL)
def str(self):
return self.libelle_generaliste
So my problem is that I canât join these three tables at the same time and get the information in one. But I can put two tables in relation to each other which is this.
labo=labo.objects.all().select_related('patient')
but how to put these three tables together. Please help me.