本文介绍了无法根据请求用户使autocomplete_light过滤器taggit标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这与这两个应用无关,我们深表歉意。以下片段会让我一旦切片被取消就无法过滤查询:



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)


解决方案

好的,尝试这样:

  def cho ices_for_request(self):
self.choices = self.choices.filter(cartao__user = self.request.user)
返回超级(TagAutocomplete,self).choices_for_request()

我很抱歉,我的文档中有错误... arggggg!




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 !

这篇关于无法根据请求用户使autocomplete_light过滤器taggit标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 16:59