' update_fields'是此函数的无效关键字参数

时间:2016-08-12 13:01:13

标签: django

我在保存django模式表单时收到此错误消息

' update_fields'是此函数的无效关键字参数 我不知道为什么会发生这种错误 在更新和插入操作中获得相同的错误 这是我的观看代码

form = CompanyForm(request.POST, instance=company)
if form.is_valid():
       company = form.save(request.user)

我的模态表格

class CompanyForm(forms.ModelForm):
    class Meta:
        model = Company
        fields = ('name','organisation', 'currency')

    def __init__(self, *args, **kwargs):
        super(CompanyForm, self).__init__(*args, **kwargs)
        if self.instance.id:
            self.fields['currency'].widget.attrs['readonly'] = True

    def clean_currency(self):
        if self.instance.id:
            return self.instance.currency
        return self.cleaned_data.get('currency')

    def save(self, operator, commit=True):
        company = super(CompanyForm, self).save(commit=False)
        company.operator = operator
        company.save()
        return company

堆栈跟踪在下面给出

环境:

Request Method: POST
Request URL: http://stage.site.net/manage/companies/1/edit/

Django Version: 1.9
Python Version: 2.7.9
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.sites',
 'django.contrib.admindocs',
 'django.contrib.staticfiles',
 'django.contrib.postgres',
 'axes',
 'mailer',
 'compressor',
 'lib',
 'cpanel',
 'systems',
 'profiles',
 'frontend',
 'documents',
 'finance',
 'themes',
 'media',
 'plugins',
 'rosetta',
 'debug_toolbar')
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'middlewares.SiteMiddleWare',
 'middlewares.StripHtmlCommentsMiddleware')



Traceback:

File "/var/django_apps/site/cms/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/var/django_apps/site/cms/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/var/django_apps/site/cms/env/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "./apps/adminmanage/views.py" in company_edit
  117.             company = form.save(request.user)

File "./apps/systems/forms.py" in save
  136.         company.save()

File "/var/django_apps/site/cms/env/local/lib/python2.7/site-packages/django/db/models/base.py" in save
  700.                        force_update=force_update, update_fields=update_fields)

File "/var/django_apps/site/cms/env/local/lib/python2.7/site-packages/django/db/models/base.py" in save_base
  737.                                    update_fields=update_fields, raw=raw, using=using)

File "/var/django_apps/site/cms/env/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
  192.             response = receiver(signal=self, sender=sender, **named)

File "/var/django_apps/site/cms/env/local/lib/python2.7/site-packages/django/db/models/base.py" in __init__
  443.                 raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])

Exception Type: TypeError at /manage/companies/1/edit/
Exception Value: 'update_fields' is an invalid keyword argument for this function

1 个答案:

答案 0 :(得分:1)

解决了问题 不正确的接收者提出这个问题,

@receiver(models.signals.post_save)