I would like to add a field on the ModelAdmin.change_view() to filter my inline objects.
Based on this solution I tried to inject extra_context into it:
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)
Unfortunately, the method variable extra_context
is a unicode string and django raises:
TypeError, Exception Value: 'unicode' object does not support item assignment
on calling /admin/core/process/5/
.
Is it possible to insert the object_id into the extra_context dictionary to inject a form to filter?