Django Haystack Search by Django Model PK

Is there a convenient hook for finding hay results on Django PK? Something like (this does not work)

SearchQuerySet().filter(pk=12) 

An alternative is that I would add an explicit field to SearchIndex for the pk model, but this seems wasteful since the query results from Haystack contain the base django pk model

0
django django-haystack
source share
2 answers

After me worked:

 SearchQuerySet().models(Product).filter(django_id='10229') 
+4
source share

In Haystack, you can have many different applications and models, so you must also explicitly specify the names for the haystack request, because inside Haystack it will create identifiers like app.model.pk ... For example. you may have a "Catalog" application, inside which you have a "Product" model and want to filter for pk = 12:

 SearchQuerySet().filter(pk='catalog.product.12') 

will do the trick.

+1
source share

All Articles