diff options
Diffstat (limited to '')
-rw-r--r-- | ctrack/caf/managers.py | 8 | ||||
-rw-r--r-- | ctrack/caf/views.py | 3 |
2 files changed, 7 insertions, 4 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 diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py index e37bbe2..23727d9 100644 --- a/ctrack/caf/views.py +++ b/ctrack/caf/views.py @@ -27,7 +27,8 @@ class ListApplicableSystem(ListView): # probably need a custom manager for this - to add in the POC def get_queryset(self): - ess = ApplicableSystem.objects.all().order_by("organisation__name") +# ess = ApplicableSystem.objects.all().order_by("organisation__name") + ess = ApplicableSystem.objects.with_primary_contact() return ess def get_context_data(self, **kwargs): |