我很难将它们集成在一起,当访问'/ autocomplete / CartaoAutocomplete /'我得到“相关字段有无效的查找:icontains”。相关代码:
class Cartao(models.Model):
...
tags = TaggableManager()
...
autocomplete_light.register(Cartao,
search_fields=['tags'],
)
...
class CartaoForm(ModelForm):
tags = TagField(widget=TagWidget('CartaoAutocomplete'))
...
class CartaoAdmin(admin.ModelAdmin):
form = autocomplete_light.modelform_factory(Cartao)
admin.site.register(Cartao, CartaoAdmin)
答案 0 :(得分:1)
以下注册“Cartao”的自动完成功能,这意味着它会建议“Cartao”对象。您要做的是使用自动填充建议标记,这是标记实例。而不是:
# autocomplete_light_registry.py
autocomplete_light.register(Cartao,
search_fields=['tags'],
)
# forms.py
class CartaoForm(ModelForm):
tags = TagField(widget=TagWidget('CartaoAutocomplete'))
你应该:
# autocomplete_light_registry.py
from taggit.models import Tag
autocomplete_light.register(Tag)
# forms.py
class CartaoForm(ModelForm):
tags = TagField(widget=TagWidget('TagAutocomplete'))
如果这是正确的,请告诉我,然后我会更新文档。