From 0132f5806782834b8731b67f3e45dffa70108ec2 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 22 Nov 2024 15:54:14 -0500 Subject: [PATCH] glamr/views: Use ChainedQuerySet to export sample-based readabundance Closes #56. --- mibios/glamr/tables.py | 8 +++++++- mibios/glamr/views.py | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mibios/glamr/tables.py b/mibios/glamr/tables.py index d514fc1..384c513 100644 --- a/mibios/glamr/tables.py +++ b/mibios/glamr/tables.py @@ -339,7 +339,13 @@ class Meta: exclude = ['id'] def customize_queryset(self, qs): - if not self.is_for_export(): + if self.is_for_export(): + if isinstance(qs, ChainedQuerySet): + if qs.fk_field is self._meta.model._meta.get_field('sample'): + # use sample+ref uniq constraint index, so existing order + # by ref_id + qs.iterate_sortkey = 'ref_id' + else: # For normal HTML table get the function names, don't need or want # those for export qs = qs.prefetch_related('ref__function_names') diff --git a/mibios/glamr/views.py b/mibios/glamr/views.py index 238ad14..7830ec8 100644 --- a/mibios/glamr/views.py +++ b/mibios/glamr/views.py @@ -194,6 +194,12 @@ def get_export_queryset(self, export_option): # more intricate options would need to be implemented by inheriting # views. remote_field = self.get_export_remote_field(export_option) + if self.model is Sample: + return remote_field.model.objects.all().split_by_fk( + remote_field, + self.get_queryset(), + ) + f = {remote_field.name + '__in': self.get_queryset()} return remote_field.model.objects.filter(**f)