SQL optimisation of detailed training record

This commit is contained in:
2021-12-28 12:13:08 +00:00
parent 7c830ee7e5
commit 732affa0b2
3 changed files with 6 additions and 3 deletions

View File

@@ -67,7 +67,10 @@ class TrainingItem(models.Model):
return "{}.{}".format(self.category.reference_number, self.reference_number) return "{}.{}".format(self.category.reference_number, self.reference_number)
def __str__(self): def __str__(self):
return "{} {}".format(self.number, self.name) name = "{} {}".format(self.number, self.name)
if not self.active:
name += " (inactive)"
return name
@staticmethod @staticmethod
def user_has_qualification(item, user, depth): def user_has_qualification(item, user, depth):

View File

@@ -22,7 +22,7 @@
</thead> </thead>
<tbody> <tbody>
{% for object in object_list %} {% for object in object_list %}
<tr id="row_item"> <tr id="row_item" {% if request.user.is_superuser and not object.item.active %}class="text-warning"{%endif%}>
<th scope="row" class="align-middle" id="cell_name">{{ object.item }}</th> <th scope="row" class="align-middle" id="cell_name">{{ object.item }}</th>
<td class="table-{% colour_from_depth object.depth %}">{{ object.get_depth_display }}</td> <td class="table-{% colour_from_depth object.depth %}">{{ object.get_depth_display }}</td>
<td>{{ object.date }}</td> <td>{{ object.date }}</td>

View File

@@ -51,7 +51,7 @@ class TraineeItemDetail(generic.ListView):
template_name = 'trainee_item_list.html' template_name = 'trainee_item_list.html'
def get_queryset(self): def get_queryset(self):
return models.Trainee.objects.get(pk=self.kwargs['pk']).qualifications_obtained.all() return models.Trainee.objects.get(pk=self.kwargs['pk']).qualifications_obtained.all().order_by('-date').select_related('item', 'trainee', 'supervisor', 'item__category')
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)