如果这与这两个应用程序无关,我道歉。下面的代码片段会告诉我“切片一旦切片就无法过滤查询”:
models.py
class Cartao(models.Model):
...
user = models.ForeignKey(settings.AUTH_USER_MODEL)
tags = TaggableManager()
autocomplete_light_registry.py
import autocomplete_light
from taggit.models import Tag
class TagAutocomplete(autocomplete_light.AutocompleteModelBase):
autocomplete_js_attributes={'placeholder': 'Ex: pessoal, serviços',}
def choices_for_request(self):
choices = super(TagAutocomplete, self).choices_for_request()
return choices.filter(cartao__user=self.request.user)
autocomplete_light.register(Tag, TagAutocomplete)
答案 0 :(得分:4)
好的,试试这样:
def choices_for_request(self):
self.choices = self.choices.filter(cartao__user=self.request.user)
return super(TagAutocomplete, self).choices_for_request()
我很抱歉,我的文档中有错误... arggggg!
感谢您的反馈!