python - django-advanced-filters 'grp_tags' 不是有效的标签库

标签 python django django-advanced-filters

我在 python2.7 上使用 django-advanced-filters 和 django 1.8 django-高级过滤器==1.0.1 django 大括号==1.4.0 django-easy-select2==1.2.5

它工作正常,但是当我尝试修改过滤器时,它失败了: 模型.py:

from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _

class SalesRep(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    email = models.EmailField(_('email address'), blank=True)
    duty = models.CharField(max_length=30, blank=True)
    def __unicode__(self):
        return '{} {}'.format(self.first_name, self.last_name)


class Client(models.Model):
    VALID_LANGUAGES = (
        ('en', 'English'),
        ('sp', 'Spanish'),
        ('it', 'Italian'),
    )
    USERNAME_FIELD = 'email'

    language = models.CharField(max_length=8, choices=VALID_LANGUAGES, default='en')
    email = models.EmailField(_('email address'), blank=True)
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    is_active = models.BooleanField(
        _('active'), default=True,
        help_text=_('Designates whether this user should be treated as '
                    'active. Unselect this instead of deleting accounts.'))
    assigned_to = models.ForeignKey(SalesRep)
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
    def __unicode__(self):
        return '{} {}'.format(self.first_name, self.last_name)

admin.py:

from django.contrib import admin
from advanced_filters.admin import AdminAdvancedFiltersMixin
from .models import *

@admin.register(Client)
class ClientAdmin(AdminAdvancedFiltersMixin, admin.ModelAdmin):
    list_filter = ('first_name', 'last_name', 'language', 'is_active')
    advanced_filter_fields = ('language', 'first_name',
                              ('assigned_to__email', 'Sales Rep.'))

admin.site.register(SalesRep)

错误堆栈跟踪:

C:\Python27\lib\site-packages\advanced_filters\forms.py:266: RemovedInDjango19Warning: django.db.models.get_model is deprecated.
  self._model = get_model(*instance.model.split('.'))

C:\Python27\lib\site-packages\django\db\models\__init__.py:55: RemovedInDjango19Warning: The utilities in django.db.models.loading are deprecated in favor of the new application loading system.
  from . import loading

(None, <myapp.admin.ClientAdmin object at 0x00000000037AC710>, ('language', 'first_name', ('assigned_to__email', 'SalesRep.')))
Internal Server Error: /admin/advanced_filters/advancedfilter/1/
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 164, in get_response
    response = response.render()
  File "C:\Python27\lib\site-packages\django\template\response.py", line 158, in render
    self.content = self.rendered_content
  File "C:\Python27\lib\site-packages\django\template\response.py", line 133, in rendered_content
    template = self._resolve_template(self.template_name)
  File "C:\Python27\lib\site-packages\django\template\response.py", line 88, in _resolve_template
    new_template = self.resolve_template(template)
  File "C:\Python27\lib\site-packages\django\template\response.py", line 78, in resolve_template
    return loader.select_template(template, using=self.using)
  File "C:\Python27\lib\site-packages\django\template\loader.py", line 64, in select_template
    return engine.get_template(template_name, dirs)
  File "C:\Python27\lib\site-packages\django\template\backends\django.py", line 30, in get_template
    return Template(self.engine.get_template(template_name, dirs))
  File "C:\Python27\lib\site-packages\django\template\engine.py", line 167, in get_template
    template, origin = self.find_template(template_name, dirs)
  File "C:\Python27\lib\site-packages\django\template\engine.py", line 141, in find_template
    source, display_name = loader(name, dirs)
  File "C:\Python27\lib\site-packages\django\template\loaders\base.py", line 13, in __call__
    return self.load_template(template_name, template_dirs)
  File "C:\Python27\lib\site-packages\django\template\loaders\base.py", line 23, in load_template
    template = Template(source, origin, template_name, self.engine)
  File "C:\Python27\lib\site-packages\django\template\base.py", line 190, in __init__
    self.nodelist = engine.compile_string(template_string, origin)
  File "C:\Python27\lib\site-packages\django\template\engine.py", line 261, in compile_string
    return parser.parse()
  File "C:\Python27\lib\site-packages\django\template\base.py", line 341, in parse
    compiled_result = compile_func(self, token)
  File "C:\Python27\lib\site-packages\django\template\loader_tags.py", line 210, in do_extends
    nodelist = parser.parse()
  File "C:\Python27\lib\site-packages\django\template\base.py", line 341, in parse
    compiled_result = compile_func(self, token)
  File "C:\Python27\lib\site-packages\django\template\defaulttags.py", line 1159, in load
    (taglib, e))
TemplateSyntaxError: 'grp_tags' is not a valid tag library: Template library grp_tags not found, tried django.templatetags.grp_tags,django.contrib.admin.templatetags.grp_tags,django.contrib.staticfiles.templatetags.grp_tags

如何解决这个问题?

最佳答案

django-advanced-filters作者在这里。您所描述的问题已在即将发布的版本 1.0.2 中修复(将于本周末发布)。 出现这个问题的原因是我们以前依赖django-grappelli但已转向更通用的方法。

如果你实在等不及发布,你可以安装最新的开发分支 directly from the github repo像这样:

pip install https://github.com/modlinltd/django-advanced-filters/archive/develop.zip

关于python - django-advanced-filters 'grp_tags' 不是有效的标签库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36098971/

相关文章:

python - 使用 Python Flask 上传 CSV 文件并进行处理

python - 将 Python 列表发布到 Node.js 服务器,期望有效负载由包含 JSON 的数组组成

python - 使用 IN 运算符在 pandas.Series 中查找字符串

python - 你如何在 python 中反转整数的有效位?

django - Django唯一约束+表单错误

python - 在 Django 模型中使用 Trigram (gin_trgm_ops) 创建 Gin 索引

python - django 上长时间运行的守护进程