How to return only indexed objects of a certain type in Haystack

Is it possible to use SearchQuerySet and limit the results to only a specific indexed model? If I add Note and NoteIndex to Haystack, can I only output results that correspond to Note instances?

EDIT:

I looked and found that there is a reserved field called django_ct, which is stored on each indexed model. Can I filter in this field? What values ​​are required?

DOUBLE EDITING:

Nevermind After reading the Haystack source code, django_ct is the "appname.modelname" inside and can be requested using SearchQuerySet.filter (django_ct = 'appname.modelname')

+1
source share
1 answer

According to Haystack's documentation, the SearchQueryset object has a method called models () that limits the results for these models.

eg.

SearchQuerySet().models(BlogEntry, Comment).filter(content='foo') 

As you can see, it uses the actual model class. I assume that it uses this to search for content to execute a filter.

+1
source

Source: https://habr.com/ru/post/1441645/


All Articles