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)
有帮助吗?

解决方案

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 !

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top