[Answer]-Django ORM call manager method from another manager?

1👍

You need to change:

from myir import models

to

from myir.models import DependentPatientID

The reason being, you might have already done from django.db import models and the names are conflicting.

Now,

class DependentPatientIDManager( models.Manager ):
    def get_patient_ids(self, dependent ):
        dpid = self.model.objects.get( dependent = dependent.id )
        return dpid 

returns an object, and not a queryset. So, DependentPatientID.objects.get_patient_ids(d)[0] would fail.

So try this

if connectedOnly:
    from myir.models import DependentPatientID
    patient_id_integer = 0
    dep_patient_id = DependentPatientID.objects.get_patient_ids(d) 
    if dep_patient_id:
        patient_id_integer = dep_patient_id.patient_id_integer
        results = [d for d in results if patient_id_integer == 0]

        #Or just

        if not patient_id_integer:
            results = []

Leave a comment