Answer the question
In order to leave comments, you need to log in
How to index only those models\rows where some_field=some_value?
I am using django-oscar + Solr + haystack.
*===============================================================================================================*
| id | partner_sku|price_currency|price_excl_tax|num_in_stock|date_created|date_updated|partner_id|product_id|
|"10451"|"S0010436" | "USD" | 74.00 | 20 |'some_date' |'some_date' | 1 | 5992 |
|"10452"|"S0010436" | "USD" | 80.00 | 0 |'some_date' |'some_date' | 2 | 5992 |
*===============================================================================================================*
class ProductIndexes(CelerySearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(
document=True, use_template=True,
template_name='search/indexes/cpu/item_text.txt')
upc = indexes.CharField(model_attr="upc", null=True)
title = indexes.CharField(model_attr='title', null=True)
# Fields for faceting
product_class = indexes.CharField(null=True, faceted=True)
category = indexes.MultiValueField(null=True, faceted=True)
partner = indexes.MultiValueField(null=True, faceted=True)
price = indexes.FloatField(null=True, faceted=True)
vendor = indexes.CharField(null=True, faceted=True)
rating = indexes.IntegerField(null=True, faceted=True)
num_in_stock = indexes.BooleanField(null=True, faceted=True)
# Spelling suggestions
suggestions = indexes.FacetCharField()
date_created = indexes.DateTimeField(model_attr='date_created')
date_updated = indexes.DateTimeField(model_attr='date_updated')
def get_model(self):
return get_model('catalogue', 'Product')
def index_queryset(self, using=None):
return self.get_model().objects.filter(stockrecords__partner_id=2).order_by('-num_in_stock')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question