我正在尝试存储在另一个(ajax)请求中需要访问的ChangeList对象。我需要从变更列表中获取(过滤后的)查询集。这是(部分)代码:
class TimeReportEntryAdmin(admin.ModelAdmin):
...
def changelist_view(self, request, extra_context=None):
changelist = ChangeList(request, self.model, 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_max_show_all, self.list_editable, self)
# i'd like to store the changelist object here
...
我尝试使用以下方法将ChangeList对象存储在缓存中:
cache.set("time_report_changelist_%s" % request.user, changelist, 0);
这给我一个PicklingError:Can't pickle <type 'module'>: attribute lookup __builtin__.module failed
并且无法在会话中进行存储:
request.session["time_report_changelist"] = changelist
这给了我一个TypeError:<django.contrib.admin.views.main.ChangeList object at 0x1051da890> is not JSON serializable
也许有完全不同的方法吗?感谢您的帮助。