【发布时间】:2019-11-11 03:51:21
【问题描述】:
我是 django 弹性搜索的新手...
当我运行这个命令时,python3 manage.py search_index --rebuild
它让我犯了这个错误:我没有弄错它
File "/home/pyking/.local/lib/python3.6/site-packages/django_elasticsearch_dsl/registries.py", line 39, in register_document
django_meta = getattr(document, 'Django')
AttributeError: type object 'PostDocument' has no attribute 'Django'
这是我的documents.py
from django_elasticsearch_dsl import DocType, Index
from blog2.models import Article
posts = Index('articles')
@posts.doc_type
class PostDocument(DocType):
class Meta:
model = Article
fields = [
'alias',
'author',
'title',
'body',
'category',
]
这是我的模型:
class Article(models.Model):
alias = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='author')
title = models.CharField(max_length=200)
body = models.TextField()
category = models.ForeignKey(Category, on_delete=models.CASCADE)
我没有发现我的代码有什么问题,即使它没有触发我的代码问题,它也触发了我一些奇怪的错误..
【问题讨论】:
-
首先你应该使用
Document类来声明文档而不是DocType,因为在ES 7.0的API中不推荐使用映射类型(即DocType)
标签: django elasticsearch django-rest-framework elasticsearch-dsl elasticsearch-dsl-py