django admin use changelist_view queryset for geraldo report
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 wor开发者_StackOverflow社区ks 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?
I ended up using the actions feature of the admin and used the queryset passed into that.
精彩评论