Returns a dictionary of all of the stored fields from the SearchIndex. Useful for serializing results. Only returns the fields Haystack's indexes are aware of as being 'stored'.
(self)
| 201 | return additional_fields |
| 202 | |
| 203 | def get_stored_fields(self): |
| 204 | """ |
| 205 | Returns a dictionary of all of the stored fields from the SearchIndex. |
| 206 | |
| 207 | Useful for serializing results. Only returns the fields Haystack's |
| 208 | indexes are aware of as being 'stored'. |
| 209 | """ |
| 210 | if self._stored_fields is None: |
| 211 | from haystack import connections |
| 212 | |
| 213 | try: |
| 214 | index = ( |
| 215 | connections[DEFAULT_ALIAS].get_unified_index().get_index(self.model) |
| 216 | ) |
| 217 | except NotHandled: |
| 218 | # Not found? Return nothing. |
| 219 | return {} |
| 220 | |
| 221 | self._stored_fields = {} |
| 222 | |
| 223 | # Iterate through the index's fields, pulling out the fields that |
| 224 | # are stored. |
| 225 | for fieldname, field in index.fields.items(): |
| 226 | if field.stored is True: |
| 227 | self._stored_fields[fieldname] = getattr(self, fieldname, "") |
| 228 | |
| 229 | return self._stored_fields |
| 230 | |
| 231 | def __getstate__(self): |
| 232 | """ |