【发布时间】:2015-05-07 11:26:34
【问题描述】:
我想在 ModelAdmin.change_view() 上添加一个字段来过滤我的内联对象。
基于this solution 我尝试将extra_context 注入其中:
class ProcessAdmin(admin.ModelAdmin):
inlines = [StepInline,]
exclude = ('steps',)
prepopulated_fields = {'name_slug': ('name',)}
def change_view(self, request, extra_context=None):
print(extra_context)
extra = extra_context or {}
extra['filter_form'] = FilterForm()
return super(ProcessAdmin, self).change_view(request, extra_context=extra)
不幸的是,方法变量extra_context是一个unicode字符串,django引发了:
TypeError, Exception Value: 'unicode' object does not support item assignment
致电/admin/core/process/5/。
是否可以将object_id插入extra_context字典注入表单进行过滤?
【问题讨论】:
标签: django django-admin django-1.7