How to add individual objects to django haystack?
I have a search index that I have created using Solr. I want to add individual django objects to the search index.
To remove objects from the solr database we use remove_object .
some = SomFooModel.objects.get(pk=1)
foo = FooIndex()
foo.remove_object(some) #This works
To add it, is there something like add_object or a work around here ?
What I want is.
foo.add_object(some). # there is no such thing
This also does not work. It does not add the object to index.
foo.update_object(some)
I have tried reading the django-haystack documentation but there seems to be nothing that might help.
I did not read the documentation well enough as a result I messed up on the QuerySet part.
foo.update_object(some)
The above does add the object to the index. Its just that I was not searching for it properly. I was searching for the object after removing it in the following way.
SearchQuerySet().filter(foo=some.foo)
This gave a empty query set always.
SearchQuerySet().models(SomFooModel).filter(foo = some.foo)
This gives the correct result.
Reference
链接地址: http://www.djcxy.com/p/26838.html下一篇: 如何添加单个对象到Django干草堆?