Reputation: 1448
I have a two two models: Doctor
and Patient
. Doctor is defined as follows:
class Doctor(models.Model):
patients = ManyToManyField('patients.Patient', related_name="%(class)ss", blank=True)
I want to get all the doctors that have a specific patient. I tried:
doctors = Doctor.objects.filter(patients__contains=patient)
it doesnt' seem to work...any idea?
Upvotes: 0
Views: 566
Reputation: 88549
patients
expects a integer value, which is not supported for contains
query
Try
patient = 1
doctors = Doctor.objects.filter(patients=patient)
or
patients = [1,2,3,4]
doctors = Doctor.objects.filter(patients__in=patients)
Upvotes: 1