简体   繁体   English

django-taggit在admin中获取错误

[英]Getting error with django-taggit with admin

In a Django project I installed django_taggit. 在Django项目中,我安装了django_taggit。 I'm getting this error when I syncdb my project. 我在同步项目时收到此错误。

AttributeError: 'TaggableManager' object has no attribute 'related'

My models.py something like this... 我的models.py是这样的...

from taggit.managers import TaggableManager

class Post(models.Model):
    title = models.CharField(max_length=100)
    tags = TaggableManager()

and admin.py something like this... 和admin.py这样的东西...

from django.contrib import admin

admin.site.register(Post)

Django admin is trying to use the TaggableManager to manage your post objects. Django管理员正在尝试使用TaggableManager来管理您的发布对象。 You need to be careful when using custom managers; 使用自定义管理器时需要小心; as the docs specify: 文档所示

If you use custom Manager objects, take note that the first Manager Django encounters (in the order in which they're defined in the model) has a special status. 如果使用自定义Manager对象,请注意,第一个Django Django遇到的Manager(按在模型中定义的顺序)具有特殊的状态。 Django interprets the first Manager defined in a class as the “default” Manager, and several parts of Django (including dumpdata) will use that Manager exclusively for that model. Django将类中定义的第一个Manager解释为“默认” Manager,并且Django的某些部分(包括dumpdata)将对该模型专用。 As a result, it's a good idea to be careful in your choice of default manager in order to avoid a situation where overriding get_query_set() results in an inability to retrieve objects you'd like to work with. 因此,最好谨慎选择默认管理器,以避免覆盖get_query_set()导致无法检索要使用的对象的情况。

An easy way to get around this is to manually specify Post.objects first: 解决此问题的一种简单方法是先手动指定Post.objects

class Post(models.Model):
    title = models.CharField(max_length=100)
    objects = models.Manager()
    tags = TaggableManager()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM