django管理员使用changelist_view查询集来获取geraldo报告
我的管理员中有以下变量:
class ModelAdmin(admin.ModelAdmin):
qs = QuerySet
...
管理员中有以下定义:
def changelist_view(self, request, extra_context=None):
from django.contrib.admin.views.main import ChangeList
cl = ChangeList(request, self.model, list(self.list_display),
self.list_display_links, self.list_filter,
self.date_hierarchy, self.search_fields,
self.list_select_related,
self.list_per_page,
self.list_editable,
self)
ModelAdmin.qs = cl.get_query_set()
return super(ModelAdmin, self).changelist_view(request, extra_context=extra_context)
我使用它来生成带有 geraldo 报告的报告,如下所示:
def groupreport(self, request, extra_context=None):
resp = HttpResponse(mimetype='application/pdf')
report = MOdelGroupReport(queryset=ModelAdmin.qs.extra(order_by = ['project_string','code','-pub_date']))
report.generate_by(PDFGenerator, filename=resp)
return resp
它在我的开发计算机上运行良好,但是当我将其部署在 UWSGI 服务器上时,报告会打印整个查询集而不是当前过滤的查询集。有更好的方法吗?
I have the following variable in my admin:
class ModelAdmin(admin.ModelAdmin):
qs = QuerySet
...
and the following def within the admin:
def changelist_view(self, request, extra_context=None):
from django.contrib.admin.views.main import ChangeList
cl = ChangeList(request, self.model, list(self.list_display),
self.list_display_links, self.list_filter,
self.date_hierarchy, self.search_fields,
self.list_select_related,
self.list_per_page,
self.list_editable,
self)
ModelAdmin.qs = cl.get_query_set()
return super(ModelAdmin, self).changelist_view(request, extra_context=extra_context)
I'm using this to generate reports with geraldo reporting as follows:
def groupreport(self, request, extra_context=None):
resp = HttpResponse(mimetype='application/pdf')
report = MOdelGroupReport(queryset=ModelAdmin.qs.extra(order_by = ['project_string','code','-pub_date']))
report.generate_by(PDFGenerator, filename=resp)
return resp
It works well on my development machine however when I deploy it on a UWSGI server the report prints the entire queryset rather than the current filtered queryset. Is there a better way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终使用了管理员的操作功能,并使用了传递到其中的查询集。
I ended up using the actions feature of the admin and used the queryset passed into that.