SearchQuerySet() contains real model object, how?

43 views
Skip to first unread message

tanma...@utradesolutions.com

unread,
Jul 25, 2017, 1:12:23 PM7/25/17
to django-haystack
>>> results=SearchQuerySet().all()
>>> results[0]
<SearchResult: kyc_connect_data_models.storypost (pk=u'429')>
>>> results[0].object
<StoryPost: <sarahh:First Channel POst>=QmVDXJvQXTZU9DWLy7kTAmyYwRvWao9PD98KPYvZ1JXRMG>

Using djangoHaystack, postgres as db, elasticsearch for search.
I have a 'StoryPost' model which I have indexed. SearchquerySet() returns the result whic is of type `SearchResult` which is fine.
But the object it contains is the actual model object, how come? Is it referring to the actual backend db 'postgres' is this case,
or have stored the exact replica in 'elasticsearch' db. 

Subhranath Chunder

unread,
Aug 22, 2017, 11:32:33 PM8/22/17
to django-...@googlegroups.com
The search backend does store the model object.

Once the property `object` is accessed, it gets lazy loaded.

Refer to the official docs:

And the implementation of the same:

--
You received this message because you are subscribed to the Google Groups "django-haystack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-haystack+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks,
Subhranath Chunder.
Reply all
Reply to author
Forward
0 new messages