自动完成轻型注册表问题



我正在尝试将自动完成指示灯安装到我的一个表单中。我一直收到这个错误:

Institution not registered, you have registered: ['InstitutionAutocomplete']

我没有在代码中的任何地方声明或注册InstitutionAutocopmlete,所以我不知道我是如何触发这个错误的。

我有以下表格:

class AddUserAccountsForm(forms.ModelForm):
    """
    Form for adding new user financial accounts.
    """
    required_css_class = 'required'
    name = forms.ModelChoiceField(required=True, queryset=Institution.objects.all(), widget=autocomplete_light.ChoiceWidget('Institution'))
    user_accounts_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'User Name'}), label="")
    user_accounts_password = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Password'}), label="")
class Meta:
    model = Institution
    fields = ('name','user_accounts_name', 'user_accounts_password',)

这在我的autocomplete_light_registry.py中:

导入自动完成灯光

from models import Institution
autocomplete_light.register(Institution,
    search_fields = ['name'],
    attrs={
        'placeholder':'Find your institution',
        'data-autocomplete-minimum-characters':1,
    },
    widget_attrs={
        'data-widget-maximum-values':4,
        'class':'modern-style',
    },
)

这是我的html。当代码运行{{form.as_p}}时会触发此错误。

{% load staticfiles %}
<script type="text/javascript" src="{% static 'jquery.js' %}">
</script>
{% include 'autocomplete_light/static.html' %}
<form action="" method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Submit" />
    <input type="hidden" name="next" value="{{ next }}" />
</form>

urls.py是:

url(r'^profile/add_user_accounts/', UserAccountsUpdate.as_view(), name='add_user_accounts'),

在您的表格中,您必须使用"InstitutionAutocomplete"而不是"Institution"

name = forms.ModelChoiceField(required=True, 
                              queryset=Institution.objects.all(), 
                              widget=autocomplete_light.ChoiceWidget('InstitutionAutocomplete'))

相关内容

  • 没有找到相关文章

最新更新