aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/caf
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-03-06 16:20:06 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2020-03-06 16:20:06 +0000
commit17ed627cc34955bc4a186d88ea34b8697177a763 (patch)
tree26af26e7a04576ca5fbe6caa558cced529baecca /ctrack/caf
parentff85a615721dc048046b212fe07edbced8fe20fc (diff)
part way through defining a new queryset for ApplicableSystem model
Diffstat (limited to '')
-rw-r--r--ctrack/caf/managers.py8
-rw-r--r--ctrack/caf/views.py3
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):