django-haystack ordering - How do I handle this?
You must have a index in your search_indexes.py with in_stock:
class YourModel(indexes.SearchIndex): in_stock = indexes.BooleanField(model_attr='model_in_stock')
and in your urls:
sqs = SearchQuerySet().models(YourModel).order_by('-in_stock', 'score') # score is a field of haystack
In this way, you show the results first if they are in stock and then by score!
To sort on a CharField, make it storable, but not indexable.
sorted_name = indexes.CharField(indexed=False, stored=True)
If you need to have it sortable and indexable, use two different fields in the SearchIndex.