Django Haystack Search by Django Model PK
Asked Answered
E

2

0

Is there an easy hook for looking up Haystack results by Django model PK? Something like (this doesn't work)

   SearchQuerySet().filter(pk=12)

The alternative is that I would add an explicit field to the SearchIndex for the model pk, but that seems wasteful, since the queryset results from Haystack contain the underlying django model pk

Eskridge answered 16/8, 2013 at 15:28 Comment(0)
N
5

Following worked for me:

SearchQuerySet().models(Product).filter(django_id='10229')
Nineveh answered 21/11, 2013 at 20:40 Comment(0)
E
1

In Haystack you might have a lot of different Apps and Models, thus you must explicitly also name those for the haystack query, because internally Haystack will create ids like app.model.pk ... E.g. you might have an App "Catalog" inside which you have a Model "Product" and want to filter for pk=12:

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

will do the trick.

Educt answered 19/8, 2013 at 16:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.