Note that there are some explanatory texts on larger screens.

plurals
  1. POIn django-haystack, how can I use subclasses of models?
    primarykey
    data
    text
    <p>I'm trying to get django-haystack (using a xapian backend) to index my model here for search, by the <code>name</code> and <code>description</code> fields.</p> <p>I have a subclass of <code>Item</code>, <code>Device</code>, which adds a <code>manufacturer</code> field.</p> <p>The <code>Item</code> model is defined thusly:</p> <pre><code>class Item(models.Model): name = models.CharField(max_length=255, unique=True) description = models.TextField(null=True, blank=True) compatible_with = models.ManyToManyField('self', null=True, blank=True) often_with = models.ManyToManyField('self', null=True, blank=True) created_by = models.ForeignKey(User, null=True, blank=True, related_name='created_by') verified = models.BooleanField(default=False) verified_by = models.ForeignKey(User, null=True, blank=True, related_name='verified_by') date_created = models.DateField(auto_now_add=True) slug = models.SlugField(max_length=300, null=True, blank=True) </code></pre> <p>My subclass of django-haystack’s <code>SearchIndex</code> looks like this:</p> <pre><code>class ItemIndex(SearchIndex): text = CharField(document=True, use_template=True) name = CharField(model_attr='name') description = CharField(model_attr='description') site.register(Item, ItemIndex) </code></pre> <p>I have set up this template, in <code>templates/search/indexes/catalog/item_text.txt</code>:</p> <pre><code>{{ object.name }} {{ object.description }} </code></pre> <p>What do I add to <code>item_text.txt</code> such that the <code>manufacturer</code> field gets indexed, if and only if the model object is an instance of <code>Device</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload