Skip to content

Commit

Permalink
small perf optim
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalfox committed May 11, 2018
1 parent eaef910 commit 5edbba7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions staffing/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from django.utils.translation import ugettext as _
from django.template.loader import get_template
from django.template import Context
from django.db.models import Q
from django.utils.safestring import mark_safe

Expand All @@ -31,8 +32,7 @@ class MissionsTableDT(MissionsViewsMixin, BaseDatatableView):
ok_sign = mark_safe("""<span class="glyphicon glyphicon-ok" style="color:green"></span>""")

def get_initial_queryset(self):
#TODO: declare explicit join with select_related()
return Mission.objects.all()
return Mission.objects.all().select_related("lead__client__organisation__company", "subsidiary")

def filter_queryset(self, qs):
""" simple search on some attributes"""
Expand Down Expand Up @@ -67,7 +67,7 @@ def render_column(self, row, column):
else:
return self.ok_sign
elif column == "archive":
return self.archiving_template.render({"row": row})
return self.archiving_template.render(Context({"row": row}))
elif column == "mission_id":
return row.mission_id()
else:
Expand All @@ -76,5 +76,4 @@ def render_column(self, row, column):
class ActiveMissionsTableDT(MissionsTableDT):
"""Active missions table backend for datatables"""
def get_initial_queryset(self):
# TODO: declare explicit join with select_related()
return Mission.objects.filter(active=True)
return Mission.objects.filter(active=True).select_related("lead__client__organisation__company", "subsidiary")

0 comments on commit 5edbba7

Please sign in to comment.