修改了分支机构排序的逻辑:省份优先

This commit is contained in:
2026-01-12 16:04:22 +08:00
parent 8eba3f0160
commit b99c2303e5
6 changed files with 106 additions and 19 deletions

View File

@@ -228,13 +228,17 @@ def BranchAll(request):
# 生成branchinfo的视图
def Branchinfo(request):
branches = Branch.objects.all()
# 统计A型、B型、C型分支机构的数量
branches = Branch.objects.all().order_by('location', 'name')
from collections import defaultdict
branches_by_province = defaultdict(list)
for branch in branches:
branches_by_province[branch.location].append(branch)
branches_by_province = dict(sorted(branches_by_province.items()))
type_a_count = branches.filter(category='A型').count()
type_b_count = branches.filter(category='B型').count()
type_c_count = branches.filter(category='C型').count()
context = {
'branches': branches,
'branches_by_province': branches_by_province,
'type_a_count': type_a_count,
'type_b_count': type_b_count,
'type_c_count': type_c_count,