|
9 | 9 | from django.utils.encoding import force_text as force_str
|
10 | 10 | else:
|
11 | 11 | from django.utils.encoding import force_str
|
| 12 | + |
12 | 13 | from django.utils.functional import Promise
|
13 |
| -from elasticsearch_dsl.field import ( |
| 14 | +from elasticsearch.dsl.field import ( |
14 | 15 | Boolean,
|
15 | 16 | Byte,
|
16 | 17 | Completion,
|
|
22 | 23 | GeoShape,
|
23 | 24 | Integer,
|
24 | 25 | Ip,
|
| 26 | + Keyword, |
25 | 27 | Long,
|
26 | 28 | Nested,
|
27 | 29 | Object,
|
28 | 30 | ScaledFloat,
|
| 31 | + SearchAsYouType, |
29 | 32 | Short,
|
30 |
| - Keyword, |
31 | 33 | Text,
|
32 |
| - SearchAsYouType, |
33 | 34 | )
|
34 | 35 |
|
35 | 36 | from .exceptions import VariableLookupError
|
@@ -100,36 +101,24 @@ class ObjectField(DEDField, Object):
|
100 | 101 | def _get_inner_field_data(self, obj, field_value_to_ignore=None):
|
101 | 102 | data = {}
|
102 | 103 |
|
103 |
| - if hasattr(self, 'properties'): |
104 |
| - for name, field in self.properties.to_dict().items(): |
105 |
| - if not isinstance(field, DEDField): |
106 |
| - continue |
| 104 | + doc_instance = self._doc_class() |
| 105 | + for name, field in self._doc_class._doc_type.mapping.properties._params.get( |
| 106 | + 'properties', {}).items(): # noqa |
| 107 | + if not isinstance(field, DEDField): |
| 108 | + continue |
| 109 | + |
| 110 | + if field._path == []: |
| 111 | + field._path = [name] |
107 | 112 |
|
108 |
| - if field._path == []: |
109 |
| - field._path = [name] |
| 113 | + # This allows for retrieving data from an InnerDoc with prepare_field_name functions. |
| 114 | + prep_func = getattr(doc_instance, 'prepare_%s' % name, None) |
110 | 115 |
|
| 116 | + if prep_func: |
| 117 | + data[name] = prep_func(obj) |
| 118 | + else: |
111 | 119 | data[name] = field.get_value_from_instance(
|
112 | 120 | obj, field_value_to_ignore
|
113 | 121 | )
|
114 |
| - else: |
115 |
| - doc_instance = self._doc_class() |
116 |
| - for name, field in self._doc_class._doc_type.mapping.properties._params.get( |
117 |
| - 'properties', {}).items(): # noqa |
118 |
| - if not isinstance(field, DEDField): |
119 |
| - continue |
120 |
| - |
121 |
| - if field._path == []: |
122 |
| - field._path = [name] |
123 |
| - |
124 |
| - # This allows for retrieving data from an InnerDoc with prepare_field_name functions. |
125 |
| - prep_func = getattr(doc_instance, 'prepare_%s' % name, None) |
126 |
| - |
127 |
| - if prep_func: |
128 |
| - data[name] = prep_func(obj) |
129 |
| - else: |
130 |
| - data[name] = field.get_value_from_instance( |
131 |
| - obj, field_value_to_ignore |
132 |
| - ) |
133 | 122 |
|
134 | 123 | # This allows for ObjectFields to be indexed from dicts with
|
135 | 124 | # dynamic keys (i.e. keys/fields not defined in 'properties')
|
|
0 commit comments