From 03da535881795dd111860169cbc81a19f94cbd12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Szulc?= Date: Thu, 31 Oct 2024 13:25:04 +0100 Subject: [PATCH] Fix data center asset export not getting filter from request --- src/ralph/admin/mixins.py | 3 --- src/ralph/data_center/admin.py | 7 ------- src/ralph/data_importer/resources.py | 8 ++++++++ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/ralph/admin/mixins.py b/src/ralph/admin/mixins.py index c0496a115a..f359061786 100644 --- a/src/ralph/admin/mixins.py +++ b/src/ralph/admin/mixins.py @@ -421,9 +421,6 @@ def get_export_queryset(self, request): ) if resource_prefetch_related: queryset = queryset.prefetch_related(*resource_prefetch_related) - # cast to list to consider all prefetch_related (django-import-export - # use queryset.iterator() to "save memory", but then for every row - # sql queries are made to fetch all m2m relations) return list(queryset) def get_export_resource_class(self): diff --git a/src/ralph/data_center/admin.py b/src/ralph/data_center/admin.py index 32625631ae..f2d72b5e9c 100644 --- a/src/ralph/data_center/admin.py +++ b/src/ralph/data_center/admin.py @@ -490,13 +490,6 @@ class DataCenterAssetAdmin( }), ) - def get_export_queryset(self, request): - return DataCenterAsset.polymorphic_objects.select_related( - *self.list_select_related - ).polymorphic_prefetch_related( - DataCenterAsset=['tags', 'ethernet_set__ipaddress', 'parent__ethernet_set__ipaddress'], - ) - def get_multiadd_fields(self, obj=None): multiadd_fields = [ {'field': 'sn', 'allow_duplicates': False}, diff --git a/src/ralph/data_importer/resources.py b/src/ralph/data_importer/resources.py index 6f4faf5671..4e9634fab7 100644 --- a/src/ralph/data_importer/resources.py +++ b/src/ralph/data_importer/resources.py @@ -306,8 +306,16 @@ class DataCenterAssetResource(ResourceWithPrice, RalphModelResource): class Meta: model = physical.DataCenterAsset select_related = ( + 'model__manufacturer', 'model__category', 'service_env__service', 'service_env__environment', 'rack__server_room__data_center', + 'configuration_path', + 'property_of', + 'parent', + 'budget_info', + ) + prefetch_related = ( + 'tags', 'ethernet_set__ipaddress', 'parent__ethernet_set__ipaddress', ) exclude = ('content_type', 'asset_ptr', 'baseobject_ptr', 'connections')