from django.shortcuts import render from common.utils.page_helper import paginate_query_and_assign_numbers from .models import DepartmentOperationalData def department_operational_data_list_view(request): # 声明查询集 query_set = DepartmentOperationalData.objects.all().order_by('-year_month') # 获取查询参数 year_month = request.GET.get('year_month', '') department = request.GET.get('department', '') # 根据提供的参数进行筛选 if year_month: query_set = query_set.filter(year_month__icontains=year_month) if department: query_set = query_set.filter(department__icontains=department) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&year_month={}&department={}'.format(year_month, department) fields = [ {"label": "一级部门", "field": "department", "type": "text", "is_show": 1, "is_add": 1}, {"label": "年月", "field": "year_month", "type": "text", "is_show": 1, "is_add": 1}, {"label": "当月收入", "field": "current_month_revenue", "type": "number", "is_show": 1, "is_add": 1}, {"label": "当月新增收入", "field": "current_month_new_revenue", "type": "number", "is_show": 1, "is_add": 1}, {"label": "当月存量收入", "field": "current_month_existing_revenue", "type": "number", "is_show": 1, "is_add": 1}, {"label": "当月成本", "field": "current_month_cost", "type": "number", "is_show": 1, "is_add": 1}, {"label": "毛利润", "field": "gross_profit", "type": "number", "is_show": 1, "is_add": 1}, {"label": "税金及附加", "field": "taxes_and_surcharges", "type": "number", "is_show": 1, "is_add": 1}, {"label": "费用", "field": "expenses", "type": "number", "is_show": 1, "is_add": 1}, {"label": "营业利润", "field": "operating_profit", "type": "number", "is_show": 1, "is_add": 1}, {"label": "经营性现金流", "field": "operational_cash_flow", "type": "number", "is_show": 1, "is_add": 1}, ] # 准备上下文 context = { 'items': items, 'id_name': 'year_month', 'query_params': query_params, 'model_config': {"app_label": "your_app_label", "model_name": "DepartmentOperationalData", "html_name": "department_operational_data_list"}, 'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "经营管理", "name": "index"}, {"title": "各一级部门经营情况", "name": "department_operational_data_list"}], 'filters': [ {"type": "text", "id": "year_month", "name": "year_month", "label": "年月", "placeholder": "请输入年月"}, {"type": "text", "id": "department", "name": "department", "label": "一级部门", "placeholder": "请输入一级部门"} ], 'table_columns': fields, 'show_button': {"add": True, "modify": True, "download": True, "upload": True}, } return render(request, 'fin_tbl/fd_list.html', context)