Extending the admin import form for django import_export

二次信任 提交于 2019-12-01 18:58:24

I know, this is an old post, but I ran into this, when looking on how to override the import_action. Your error is here: super().import_action(self, request, *args, **kwargs)

You should call it without the self:

super().import_action(request, *args, **kwargs)

or for older python:

super(MyModelAdmin, self).import_action(request, *args, **kwargs)

    def import_action(self, request, *args, **kwargs):
       response = super(MyModelAdmin, self).import_action(request, *args, **kwargs)
       context = response.context_data
       import_formats = self.get_import_formats()
       context['form'] = CustomImportForm(RelatedModel, import_formats, request.POST or None, request.FILES or None)
       return TemplateResponse(request, [self.import_template_name], context)

Avoid reimplementing either import_action() or process_import(); partially because they're fairly complex and fragile methods, but more importantly because there are neater ways of doing this using the existing hooks in the Import/Export API. See this answer for more details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!