View How the SearchIndex "template" (_text.txt) file renders

100 views
Skip to first unread message

Joe Jasinski

unread,
Feb 2, 2012, 1:02:35 PM2/2/12
to django-...@googlegroups.com
Hi all, 

I'm creating some search indexes, but I'm trying to determine if I'm doing it right and am including the correct fields.  Is there a way to view how the indexes would render kind of like viewing a Django template.... for the aim of testing and debugging?  I'm doing a complex many to many query in the template, and want to make sure it's rendering correctly. 

I'm using a Whoosh search backend with django-haystack 2.0.0-beta.  

# templates/search/indexes/core/product_text.txt
{{ object.id }}
{{ object.subcategory }}
{{ object.description }}
{% for cp in object.categoryproduct_set.all %}
  {{ cp.category }}
{% endfor %}

Stephen Burrows

unread,
Feb 6, 2012, 10:52:05 PM2/6/12
to django-...@googlegroups.com
One option would be to manually render the template. From a shell:

>>> from django.template import loader, Context
>>> from myapp.models import MyModel
>>> t = loader.get_template('search/indexes/core/product_text.txt')
>>> c = Context({'object': MyModel.objects.get(pk=1)})
>>> t.render(c)
Reply all
Reply to author
Forward
0 new messages