I am working on getting the "add another" popup to work with django-autocomplete_light
.
我正在努力获得“添加另一个”弹出窗口以使用django-autocomplete_light。
Following along in the docs:
跟随文档:
http://django-autocomplete-light.readthedocs.org/en/latest/addanother.html
http://django-autocomplete-light.readthedocs.org/en/latest/addanother.html
I have set up my URLs:
我已经设置了我的网址:
import autocomplete_light.shortcuts as al
from AlmondKing.FinancialLogs import models
from AlmondKing.FinancialLogs import forms
urlpatterns = [
url(r'^branches/autocreate/$', al.CreateView.as_view(
model=models.CompanyBranch, form_class=forms.CompanyBranch),
name='branch_autocreate'),
]
and my autocomplete_light_registry.py
和我的autocomplete_light_registry.py
al.register(CompanyBranch,
search_fields=['^branch_name'],
attrs={
'placeholder': 'Branch',
'data-autocomplete-minimum-characters': 1,
},
widget_attrs={
'data-widget-maximum-values': 1,
'class': 'modern-style',
},
add_another_url_name='company:branch_autocreate',
)
However, when I click the plus sign to add a new related object, I get the following error:
但是,当我单击加号添加新的相关对象时,我收到以下错误:
TypeError at /company/branches/autocreate/
/ company / branches / autocreate /中的TypeError
'initial' is an invalid keyword argument for this function
'initial'是此函数的无效关键字参数
I've been trying to find a way to do this for a while and I'm so close!
我一直试图找到一种方法来做这件事,我很亲密!
Now, I am hoping someone can read the traceback and help me understand what went wrong:
现在,我希望有人可以阅读回溯并帮助我理解出了什么问题:
Environment:
Request Method: GET
Request URL: http://localhost:8000/company/branches/autocreate/?_popup=1&winName=id_branch
Django Version: 1.8.2
Python Version: 3.4.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'AlmondKing.InventoryLogs',
'AlmondKing.FinancialLogs',
'AlmondKing.AKGenius',
'autocomplete_light')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'AlmondKing.AKGenius.middleware.RequireLoginMiddleware')
Traceback:
File "C:\Users\Adam\Envs\AlmondKing\lib\site-packages\django\core\handlers\base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Adam\Envs\AlmondKing\lib\site-packages\django\views\generic\base.py" in view
71. return self.dispatch(request, *args, **kwargs)
File "C:\Users\Adam\Envs\AlmondKing\lib\site-packages\django\views\generic\base.py" in dispatch
89. return handler(request, *args, **kwargs)
File "C:\Users\Adam\Envs\AlmondKing\lib\site-packages\django\views\generic\edit.py" in get
245. return super(BaseCreateView, self).get(request, *args, **kwargs)
File "C:\Users\Adam\Envs\AlmondKing\lib\site-packages\django\views\generic\edit.py" in get
205. form = self.get_form()
File "C:\Users\Adam\Envs\AlmondKing\lib\site-packages\django\views\generic\edit.py" in get_form
74. return form_class(**self.get_form_kwargs())
File "C:\Users\Adam\Envs\AlmondKing\lib\site-packages\django\db\models\base.py" in __init__
480. raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
Exception Type: TypeError at /company/branches/autocreate/
Exception Value: 'initial' is an invalid keyword argument for this function
1 个解决方案
#1
1
Try this:
尝试这个:
add_another_url_name='company:branch_autocreate',
add_another_url_name='branch_autocreate',
#1
1
Try this:
尝试这个:
add_another_url_name='company:branch_autocreate',
add_another_url_name='branch_autocreate',