Many_to_many --> FieldError: Related Field got invalid lookup: contains
Many_to_many --> FieldError: Related Field got invalid lookup: contains
我有两个两个模型:Doctor
和 Patient
。 Doctor定义如下:
class Doctor(models.Model):
patients = ManyToManyField('patients.Patient', related_name="%(class)ss", blank=True)
我想得到所有有特定病人的医生。
我试过了:
doctors = Doctor.objects.filter(patients__contains=patient)
它似乎不起作用...有什么想法吗?
patients
需要 整数 值,不支持contains
查询
尝试
patient = 1
doctors = Doctor.objects.filter(patients=patient)
或
patients = [1,2,3,4]
doctors = Doctor.objects.filter(patients__in=patients)
我有两个两个模型:Doctor
和 Patient
。 Doctor定义如下:
class Doctor(models.Model):
patients = ManyToManyField('patients.Patient', related_name="%(class)ss", blank=True)
我想得到所有有特定病人的医生。 我试过了:
doctors = Doctor.objects.filter(patients__contains=patient)
它似乎不起作用...有什么想法吗?
patients
需要 整数 值,不支持contains
查询
尝试
patient = 1
doctors = Doctor.objects.filter(patients=patient)
或
patients = [1,2,3,4]
doctors = Doctor.objects.filter(patients__in=patients)