|
10 | 10 | else: |
11 | 11 | from django.utils.encoding import force_str |
12 | 12 | from django.utils.functional import Promise |
13 | | -from elasticsearch_dsl.field import ( |
| 13 | +from elasticsearch.dsl.field import ( |
14 | 14 | Boolean, |
15 | 15 | Byte, |
16 | 16 | Completion, |
@@ -100,36 +100,24 @@ class ObjectField(DEDField, Object): |
100 | 100 | def _get_inner_field_data(self, obj, field_value_to_ignore=None): |
101 | 101 | data = {} |
102 | 102 |
|
103 | | - if hasattr(self, 'properties'): |
104 | | - for name, field in self.properties.to_dict().items(): |
105 | | - if not isinstance(field, DEDField): |
106 | | - continue |
| 103 | + doc_instance = self._doc_class() |
| 104 | + for name, field in self._doc_class._doc_type.mapping.properties._params.get( |
| 105 | + 'properties', {}).items(): # noqa |
| 106 | + if not isinstance(field, DEDField): |
| 107 | + continue |
107 | 108 |
|
108 | | - if field._path == []: |
109 | | - field._path = [name] |
| 109 | + if field._path == []: |
| 110 | + field._path = [name] |
110 | 111 |
|
| 112 | + # This allows for retrieving data from an InnerDoc with prepare_field_name functions. |
| 113 | + prep_func = getattr(doc_instance, 'prepare_%s' % name, None) |
| 114 | + |
| 115 | + if prep_func: |
| 116 | + data[name] = prep_func(obj) |
| 117 | + else: |
111 | 118 | data[name] = field.get_value_from_instance( |
112 | 119 | obj, field_value_to_ignore |
113 | 120 | ) |
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 | 121 |
|
134 | 122 | # This allows for ObjectFields to be indexed from dicts with |
135 | 123 | # dynamic keys (i.e. keys/fields not defined in 'properties') |
|
0 commit comments