can't make autocomplete_light filter taggit tags based on request user

好久不见. 提交于 2020-01-04 08:02:07

问题


I apologize if this has nothing to do with both apps. The following snippet will throw me a "cannot filter a query once a slice has been taken":

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)

回答1:


Ok, try like this:

def choices_for_request(self):
    self.choices = self.choices.filter(cartao__user=self.request.user)
    return super(TagAutocomplete, self).choices_for_request()

I apologize, there is an error in my documentation ... arggggg !

Thanks for your feedback !



来源:https://stackoverflow.com/questions/19319682/cant-make-autocomplete-light-filter-taggit-tags-based-on-request-user

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