Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第十章 P232 在 adminforms.py 中对 __init__ 方法进行重写的相关问题 #59

Open
voldown opened this issue Feb 11, 2021 · 0 comments

Comments

@voldown
Copy link

voldown commented Feb 11, 2021

对于文章编辑表单提交后出现 TypeError: init() got multiple values for argument ‘instance' 的解决方法如下:

def __init__(self, *args, **kwargs):
        initial = kwargs.get('initial') or {}
        instance = kwargs.get('instance')
        if instance:
            if instance.is_md:
                initial['content_md'] = instance.content
            else:
                initial['content_ck'] = instance.content
        kwargs.update({'initial': initial, 'instance': instance})
        super().__init__(*args, **kwargs)

StackOverflow 上的相关参考

https://stackoverflow.com/questions/55338745/typeerror-init-got-multiple-values-for-argument-instance
https://stackoverflow.com/questions/19672035/django-multiple-values-for-keyword-argument-initial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant