django admin - 导出为 csv
我使用以下 Django 代码片段将管理 Change_list 页面的结果导出到 csv http://djangosnippets.org/ snippets/790/
我可以使用此功能,但目前我只能让它导出 list_display
变量中定义的字段。
该函数接受一个列表(名为 fields
,见下文)作为变量,该变量定义要导出的字段,但我不知道如何将其传递到函数中。这是因为该函数是使用不包含 fields 变量的 url 模式调用的。
def admin_list_export(request, model_name, app_label, queryset=None, fields=None, list_display=True):
I am using the following Django Snippet to export the results of the admin change_list page to csv http://djangosnippets.org/snippets/790/
I have this working but currently I can only get it to export the fields which are defined in the list_display
variable.
The function accepts a list (named as fields
, see below) as a variable which defines which fields you want to export but I can't work out how to pass this into the function. This is because the function is called using the url pattern which does not include a fields variable.
def admin_list_export(request, model_name, app_label, queryset=None, fields=None, list_display=True):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够 通过url 定义中函数的参数:
您还可以将
list_display = False
传递给函数,它将忽略 ModelAdmin 上的list_display
设置并使用所有模型具有的字段!You should be able to pass parameters to the function in the url definition:
You can also pass
list_display = False
to the function and it will ignore thelist_display
setting on your ModelAdmin and use all fields the model has!