MCPcopy Create free account
hub / github.com/django-haystack/django-haystack / get_stored_fields

Method get_stored_fields

haystack/models.py:203–229  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers 1

test_stored_fieldsMethod · 0.80

Calls 2

get_unified_indexMethod · 0.80
get_indexMethod · 0.45

Tested by 1

test_stored_fieldsMethod · 0.64