Question

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)
Was it helpful?

Solution

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 !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top