问题
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