Django-taggit TaggableManager()产生管理员错误

时间:2018-08-07 13:55:09

标签: django python-3.x django-admin django-taggit

我正在研究《 Django 2示例》一书,其中我试图构建具有标记功能的博客应用程序。

我的用于包含django-taggit的代码(在通过pip安装0.22.2版本之后)如下。

将应用添加到INSTALLED_APPS

INSTALLED_APPS = [
    #...
    'blog.apps.BlogConfig',
    'taggit',
]

TaggableManager提供的django-taggit添加到Post模型中。

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
from taggit.managers import TaggableManager
# Create your models here.
class PublishedManager(models.Manager):
    def get_queryset(self):
        return super(PublishedManager, self).get_queryset().filter(status='published')


class Post(models.Model):
    STATUS_CHOICES = (
        ('draft', 'Draft'),
        ('published', 'Published'),
    )
    title = models.CharField(max_length=250)
    slug = models.SlugField(max_length=250, unique_for_date='publish')
    author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='blog_posts')
    body = models.TextField(default='')
    publish = models.DateTimeField(default=timezone.now)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='draft')

    objects = models.Manager() # The default manager.
    published = PublishedManager() # Our custom manager.
    tags = TaggableManager()
    def get_absolute_url(self):
        return reverse('blog:post_detail',
                       args=[self.publish.year,
                             self.publish.month,
                             self.publish.day,
                             self.slug])
    class Meta:
        ordering = ('publish',)

    def __str__(self):
        return self.title

当我将行tags = TaggableManager()添加到Post模型时,尝试通过管理站点添加新帖子或编辑现有帖子时收到以下错误:

TypeError: render() got an unexpected keyword argument 'renderer'

我不知道为什么会产生此错误,因此任何建议将不胜感激。

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我决定安装django-taggit 0.23.0

我输入virtualenv:pip install django-taggit==0.23.0

希望对您有所帮助。 最好的问候。

答案 1 :(得分:0)

我在此链接上找到了答案。 https://github.com/froala/django-froala-editor/issues/55

解决方案: 导航到django / forms / boundfields.py 并删除第93行(renderer = self.form.renderer)。