Different implementations for Autocomplete-light

只谈情不闲聊 提交于 2020-01-06 20:16:36

问题


I was able to implement the autocomplete-light function using a class based view format:

class UserAccountsUpdate(UpdateView):
    context_object_name = 'variable_used_in `add_user_accounts.html`'
    form_class = AddUserAccountsForm
    template_name = 'add_user_accounts.html'

    def add_user_institution_details(request):
    ###code###

With this form:

class AddUserAccountsForm(autocomplete_light.ModelForm):
    required_css_class = 'required'
    name = forms.CharField(
        required=True,
        widget=autocomplete_light.TextWidget('InstitutionAutocomplete'), 
        label="",)
class Meta:
    model = Institution
    autocomplete_fields = ('name')
    fields = ('name',) 

With urls.py:

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

However, I am trying to debug my code in the class based view (i.e. add_user_institution_details). I have decided to change from the code about by call the method directly.

So updated the view to this:

def add_user_institution_details(request):
    context_object_name = 'variable_used_in `add_user_accounts.html`'
    form_class = AddUserAccountsForm
    template_name = 'add_user_accounts.html'

    if request.method == 'POST':
        form = AddUserAccountsForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
        ### code ###

and updated urls.py to:

url(r'^add_details', add_user_institution_details),

For some reason in the second implementation, the autocomplete search box has disappears completely. What am I missing?

来源:https://stackoverflow.com/questions/33910120/different-implementations-for-autocomplete-light

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!