Skip to content

Commit dc3d89f

Browse files
authored
Adding support for Postgresql JSONField (#220)
* Adding support for postgres jsonfield * fixup * Fixing import
1 parent c62ac66 commit dc3d89f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

django_elasticsearch_dsl/documents.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
LongField,
2323
ShortField,
2424
TextField,
25-
)
25+
ObjectField)
2626
from .search import Search
2727

2828
model_field_class_to_field_class = {
@@ -49,8 +49,16 @@
4949
models.URLField: TextField,
5050
}
5151

52+
try:
53+
from django.contrib.postgres.fields import JSONField
54+
model_field_class_to_field_class[JSONField] = ObjectField
55+
except ImportError:
56+
pass
57+
58+
5259
class DocType(DSLDocument):
5360
_prepared_fields = []
61+
5462
def __init__(self, related_instance_to_ignore=None, **kwargs):
5563
super(DocType, self).__init__(**kwargs)
5664
self._related_instance_to_ignore = related_instance_to_ignore

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
django>=1.9.6
22
elasticsearch-dsl>=7.0.0,<8.0.0
3-

0 commit comments

Comments
 (0)