ADD file via upload

zf_branch
ptgkifnrw 4 months ago
parent 90ffcf644a
commit 435309f2e4

@ -0,0 +1,21 @@
#zf:从haystack导入索引相关模块
from haystack import indexes
#zf:从blog.models导入Article模型
from blog.models import Article
#zf:定义文章索引类继承自SearchIndex和Indexable
class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
#zf:定义文本字段,作为文档字段,使用模板来确定索引内容
text = indexes.CharField(document=True, use_template=True)
#zf:获取模型类的方法
def get_model(self):
#zf:返回Article模型
return Article
#zf:定义索引查询集,确定哪些数据会被索引
def index_queryset(self, using=None):
#zf:返回所有状态为已发布('p')的文章
return self.get_model().objects.filter(status='p')
Loading…
Cancel
Save