Tag: django views

在Django中获取多个checkbox的值

我有一张桌子,里面显示不同客户的不同账单: 我在我的views.py中有这样的代码: @login_required def descarga(request,id_factura): selected_values = request.POST.getlist('factura') if request.method == 'POST': form = Factura.objects.filter(id__in=selected_values) if form: (…Styling of the Excell file…) # write the header header = ['Cliente', 'Fecha de Factura', 'Tipo de Factura', 'Numero de Factura', 'Descripcion', 'Subtotal', 'IVA', 'Precio'] for hcol, hcol_data in enumerate(header): # [(0,'Header 1'), (1, 'Header 2'), (2,'Header 3'), […]

使用原始的sql导出到django中的CSV / Excel文件

在django中生成excel / csv文件的问题主要是因为我正在使用raw sql查询数据库(直接)。 我只能访问数据库而不是模型类。 这是我的代码片段。 我得到一个错误“字典”对象没有属性“todo_job” 查看代码 def query_to_dicts(query_string, *query_args): """Run a simple query and produce a generator that returns the results as a bunch of dictionaries with keys for the column values selected. """ #log.debug(str(dir(connection))) cursor = connection.cursor() #log.debug(str(dir(cursor))) cursor.execute(query_string, query_args) #log.debug(cursor.rowcount)log col_names = [desc[0] for desc in cursor.description] #log.debug(str(col_names)) while True: row […]