2016-08-12 151 views
0

我得到這個錯誤訊息節約Django的模式窗體「update_fields」是這個函數

「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

解決問題 不正確接收器使得這個問題,

@receiver(models.signals.post_save)