diff options
Diffstat (limited to 'ctrack/caf/managers.py')
-rw-r--r-- | ctrack/caf/managers.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/ctrack/caf/managers.py b/ctrack/caf/managers.py index cba8c83..4d8c134 100644 --- a/ctrack/caf/managers.py +++ b/ctrack/caf/managers.py @@ -1,8 +1,8 @@ from django.db import connection from django.db import models -import ctrack.caf.models # to deal with circular import -from ctrack.organisations.models import Organisation, Person +import ctrack.caf.models as caf_models # to deal with circular import +import ctrack.organisations.models as org_models class ApplicableSystemManager(models.Manager): @@ -16,14 +16,16 @@ class ApplicableSystemManager(models.Manager): Using Custom Managers Django docs for an example. """ with connection.cursor() as cursor: - cursor.execute(""" + cursor.execute( + """ SELECT a.id, a.name, o.id, c.id, sm.id, p.id, o.name FROM caf_applicablesystem a, organisations_organisation o, organisations_person p, caf_caf c, organisations_submode sm WHERE a.organisation_id = o.id AND a.caf_id = c.id AND p.organisation_id = o.id AND o.submode_id = sm.id AND p.primary_nis_contact = True; - """) + """ + ) result_list = [] for row in cursor.fetchall(): - org = Organisation.objects.get(pk=row[2]) + org = org_models.Organisation.objects.get(pk=row[3]) caf = ctrack.caf.models.CAF.objects.get(pk=row[3]) ass = self.model(id=row[0], name=row[1], organisation=org, caf=caf) ass.nis_contact = Person.objects.get(pk=row[5]) |