0
我似乎無法使用django-contrib用戶模型進行django-autocomplete-light工作。總是例外 '的選擇應該是一個查詢集'django-autocomplete-light與用戶 - 選擇應該是一個查詢集
這是(在autocomplete_ligh_registry.py定義)我的自動完成類:
import autocomplete_light
from django.contrib.auth.models import User
class UserAutocomplete(autocomplete_light.AutocompleteModelBase):
search_fields = ['first_name']
model = User
autocomplete_light.register(UserAutocomplete)
我的形式(forms.py):
class TransactionForm(forms.Form):
mymodel = forms.ModelChoiceField( required=True,
queryset=User.objects.all() ,
widget=autocomplete_light.ChoiceWidget('UserAutocomplete'))
當嘗試使用{{form}}進行渲染時,它會拋出一個異常:選擇應該是查詢集: 堆棧:
/home/prj/docs/projectos/.../src/autocomplete-light/autocomplete_light/widgets.py in render
choices = autocomplete.choices_for_values() ...
▶ Local vars
/home/prj/docs/projectos/.../src/autocomplete-light/autocomplete_light/autocomplete/model.py in choices_for_values
assert self.choices is not None, 'choices should be a queryset'
這是在開發中運行的django 1.6。我有用戶創建。 Django的自動補光工程確定與autocompleteListBase,例如:
class OsAutocomplete(autocomplete_light.AutocompleteListBase):
choices = ['Linux', 'BSD', 'Minix']
autocomplete_light.register(OsAutocomplete)
所以urls.py都包括註冊表,網址,註冊和JavaScript被加載。 以下這些文檔: http://django-autocomplete-light.readthedocs.org/en/latest/index.html#tutorial
任何指針?
謝謝!