.
This commit is contained in:
@@ -396,6 +396,22 @@ class Case(models.Model, AuthorMixin, QuestionMixin):
|
||||
|
||||
cimar_uuid = models.CharField(max_length=255, null=True, blank=True)
|
||||
|
||||
def get_ordered_series_details(self):
|
||||
# If the series are already prefetched, use them directly
|
||||
if hasattr(self, '_prefetched_objects_cache') and 'series' in self._prefetched_objects_cache:
|
||||
# Get the through model and sort by sort_order
|
||||
through_model = self.series.through
|
||||
# Build a mapping from series pk to through instance
|
||||
through_objs = list(through_model.objects.filter(case=self).select_related('series'))
|
||||
through_objs.sort(key=lambda x: x.sort_order)
|
||||
return through_objs
|
||||
# Otherwise, query as before
|
||||
return self.series.through.objects.filter(case=self).select_related('series').order_by('sort_order')
|
||||
|
||||
def get_ordered_series(self):
|
||||
"""Returns the series in the case in order of the SeriesDetail sort_order"""
|
||||
return [sd.series for sd in self.get_ordered_series_details()]
|
||||
|
||||
def get_app_name(self):
|
||||
return "atlas"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user