-
Notifications
You must be signed in to change notification settings - Fork 27
/
documents.py
32 lines (26 loc) · 1.01 KB
/
documents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from django_elasticsearch_dsl import Document, fields
from django_elasticsearch_dsl.registries import registry
from pydash import get
from core.collections.models import Collection
@registry.register_document
class CollectionDocument(Document):
class Index:
name = 'collections'
settings = {'number_of_shards': 1, 'number_of_replicas': 0}
last_update = fields.DateField(attr='updated_at')
public_can_view = fields.TextField(attr='public_can_view')
locale = fields.ListField(fields.KeywordField())
owner = fields.KeywordField(attr='parent_resource')
owner_type = fields.KeywordField(attr='parent_resource_type')
collection_type = fields.KeywordField(attr='collection_type')
is_active = fields.KeywordField(attr='is_active')
class Django:
model = Collection
fields = [
'name',
'full_name',
'custom_validation_schema',
]
@staticmethod
def prepare_locale(instance):
return get(instance.supported_locales, [])