diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-03-06 16:20:06 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-03-06 16:20:06 +0000 |
commit | 17ed627cc34955bc4a186d88ea34b8697177a763 (patch) | |
tree | 26af26e7a04576ca5fbe6caa558cced529baecca /ctrack/caf/managers.py | |
parent | ff85a615721dc048046b212fe07edbced8fe20fc (diff) |
part way through defining a new queryset for ApplicableSystem model
Diffstat (limited to '')
-rw-r--r-- | ctrack/caf/managers.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/ctrack/caf/managers.py b/ctrack/caf/managers.py index 3aea117..1323e38 100644 --- a/ctrack/caf/managers.py +++ b/ctrack/caf/managers.py @@ -1,6 +1,7 @@ from django.db import models -from ctrack.organisations.models import Organisation, Person +from ctrack.organisations.models import Organisation, Person, Submode +import ctrack.caf.models # to deal with circular import class ApplicableSystemManager(models.Manager): @@ -12,14 +13,15 @@ class ApplicableSystemManager(models.Manager): from django.db import connection with connection.cursor() as cursor: cursor.execute(""" - SELECT a.id, a.name, o.id, c.id, sm.descriptor, p.id, o.name + 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 = False; """) result_list = [] for row in cursor.fetchall(): org = Organisation.objects.get(pk=row[2]) - ass = self.model(id=row[0], name=row[1], organisation=org) + 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]) result_list.append(ass) return result_list |