diff --git a/backend/right_tree/api/admin.py b/backend/right_tree/api/admin.py index 248b038..a6f58f0 100644 --- a/backend/right_tree/api/admin.py +++ b/backend/right_tree/api/admin.py @@ -13,7 +13,7 @@ class ZoneAdmin(admin.ModelAdmin): class QuestionnaireAdmin(admin.ModelAdmin): - list_display = ['address_display', 'location_display', 'soil_variant', 'ecological_district', 'habitat', 'zone'] + list_display = ['address_display', 'location_display', 'soil_variant', 'ecological_district_display', 'habitat', 'zone'] actions = ['export'] @admin.display(description="Address") @@ -24,6 +24,14 @@ class QuestionnaireAdmin(admin.ModelAdmin): def location_display(self, obj): return f"({obj.location.x}, {obj.location.y})" + @admin.display(description="Ecological District") + def ecological_district_display(self, obj): + return getattr( + models.EcologicalDistrictLayer.objects.filter(geom__intersects=obj.location).first(), + "ecologic_2", + None, + ) + @admin.action(description="Export planting guides for selected questionnaires") def export(self, request, queryset): export = models.Export.objects.create(creation_date=timezone.now()) diff --git a/backend/right_tree/api/models.py b/backend/right_tree/api/models.py index 8fbc732..1d23ebc 100644 --- a/backend/right_tree/api/models.py +++ b/backend/right_tree/api/models.py @@ -208,14 +208,6 @@ class Questionnaire(models.Model): def habitat(self): return self.zone.habitat - @property - def ecological_district_layer(self): - return EcologicalDistrictLayer.objects.filter(geom__intersects=self.location).first() - - @property - def ecological_district(self): - return self.ecological_district_layer.ecologic_2 - @cached_property def address(self): return \ @@ -264,8 +256,9 @@ class Export(models.Model): _, files = storage.listdir(f"export_{self.pk}") - # halved as there are two files (csv, pdf) per questionnaire - return 0.5 * len(files) / self.questionnaires.count() + # 0.25 multiplier as there are four files per questionnaire: + # csv, filters PDF, plants PDF, merged PDF + return 0.25 * len(files) / self.questionnaires.count() def export(self): from .tasks import generate_pdf