bonjour la communauté Django
je suis débutant en Django et j’ai un problème de jointure entre ces tables ci
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
class labo(models.Model):
patient=models.ForeignKey(patient, null=True, on_delete=models.SET_NULL,related_name=‘labos’)
def str(self):
return self.libelle_labo
class specialite(models.Model):
patient=models.ForeignKey(patient, null=True, on_delete=models.SET_NULL,related_name=‘specialistes’)
class generalister(models.Model):
patient = models.ForeignKey(patient, null=True, on_delete=models.SET_NULL,related_name=‘generalisters’)
def str(self):
return self.libelle_generaliste
In fact, I want to get all the activities of a patient, further put these three tables in relation.
I’m not sure what to do about it, but I’m sure it’s a good idea to have a look at it.
def recu(request):
affichepatient=patient.objects.prefetch_related(‘labos’,‘specialistes’,‘generalisters’).all()
context={‘affichepatient’:affichepatient}
return render(request,‘recu/recu.html’,context)
Can anyone help me?