gault-millau/apps/search_indexes/documents/news.py
2019-09-06 14:52:52 +03:00

41 lines
920 B
Python

"""News app documents."""
from django.conf import settings
from django_elasticsearch_dsl import Document, Index, fields
from news.models import News
INDEX = Index(settings.ELASTICSEARCH_INDEX_NAMES[__name__])
INDEX.settings(number_of_shards=1, number_of_replicas=1)
@INDEX.doc_type
class NewsDocument(Document):
"""News document."""
title = fields.ObjectField()
subtitle = fields.ObjectField()
description = fields.ObjectField()
web_url = fields.StringField(attr='web_url')
class Django:
model = News
fields = (
'id',
'playlist',
)
def get_queryset(self):
return super().get_queryset().published()
def prepare_title(self, instance):
return instance.title
def prepare_subtitle(self, instance):
return instance.subtitle
def prepare_description(self, instance):
return instance.description