[英]Django Foreign key query
I have the following modle 我有以下型号
class PatientContact(models.Model):
uid = models.CharField(max_length=10)
name = models.CharField(max_length=100)
phone = PhoneNumberField()
class Patient(models.Model):
name = models.CharField(max_length=100)
date_of_birth = models.DateField()
contact = models.ForeignKey(PatientContact)
class Appointment(models.Model):
patient = models.ForeignKey(Patient)
time = models.DateTimeField()
I can get the list of patients registered under a user: 我可以获得在用户下注册的患者列表:
Patient.objects.filter(contact=uid) Patient.objects.filter(contact = uid)
How could I get the list of appointment for a user from the above model? 如何从上述模型中获取用户的约会列表?
Used case: 使用案例:
The list of appointments scheduled by user (uid=1234) Not sure how to perform a backward relationship to get list of appointments for a given uid. 用户安排的约会列表(uid = 1234)不确定如何执行向后关系以获取给定uid的约会列表。
如果我正确地理解了您的意思,那么这并不落后,只有两个层次:
Appointment.objects.filter(patient__contact__uid=1234)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.