瀏覽代碼

查詢定制客户信息 返回国家名

linhaohong 1 年之前
父節點
當前提交
1df326121c
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      AdminController/UserManageController.py

+ 7 - 1
AdminController/UserManageController.py

@@ -1141,14 +1141,20 @@ class UserManagement(View):
             paginator = Paginator(custom_customer_qs.order_by('id'), page_size)
             customers = paginator.page(page)
 
+            # 批量查询所有相关的国家信息
+            country_ids = custom_customer_qs.values_list('country_id', flat=True).distinct()
+            country_qs = CountryModel.objects.filter(id__in=country_ids)
+            country_map = {country.id: country.country_name for country in country_qs}
+
             customer_list = []
             for customer in customers.object_list:
+                country_name = country_map.get(customer.country_id, '')
                 customer_list.append({
                     'cId': customer.id,
                     'orderNumber': customer.order_number,
                     'name': customer.name,
                     'email': customer.email,
-                    'countryId': customer.country_id,
+                    'countryName': country_name,
                     'quantity': customer.quantity,
                     'createdTime': customer.created_time,
                 })