Trying to implement a simple ordering query on <a href="http://django-oscar.readthedocs.org/en/releases-1.1/_modules/oscar/apps/catalogue/views.html#ProductCategoryView" rel="nofollow">ProductCategoryView</a> in Django-Oscar. It should be fairly simple to implement but it's taking too much time to understand. I'm having second thoughts to go forward with Oscar or not as it seems difficult to extend.
The <a href="http://django-oscar.readthedocs.org/en/releases-1.1/_modules/oscar/apps/catalogue/views.html#ProductCategoryView" rel="nofollow">ProductCategoryView</a> returns products of a certain category. I want to sort them according to certain field in product model say
price. First I change the parent generic class from
ListView so that I can use
get_queryset method. Then I override the
get_queryset method as below and write a simple queryset in that. Still the sorting doesn't happen <strong>though the flow does go inside the
def get_queryset(self): queryset = Product.objects.filter(categories = self.category) logger.debug("inside") queryset = queryset.order_by("price") return queryset
So what methods I have to overwrite. Will there be so much trouble editing Oscar every time or I'm missing something?
P.S : I have asked lot of questions around Django/Oscar Class based view recently . So I might look like a <a href="https://meta.stackoverflow.com/questions/258206/what-is-a-help-vampire" rel="nofollow">Help Vampire</a>. Please ignore this question if that is the case.Answer1:
@Anentropic is right but let me elaborate a bit.
Oscar bases all its browse views on search engines so faceting can be used to narrow down the list of products returned. By default there are search engine integrations for <a href="http://lucene.apache.org/solr/" rel="nofollow">Solr</a> and <a href="https://www.elastic.co/products/elasticsearch" rel="nofollow">Elasticsearch</a>.
If you don't use Solr or Elasticsearch, the default implementation is
SimpleProductSearchHandler. It does not use any external services but instead <a href="https://github.com/django-oscar/django-oscar/blob/releases/1.1/src/oscar/apps/catalogue/search_handlers.py#L101-L105" rel="nofollow">calls
Product.browsable.get_queryset()</a>. That code lives in <a href="https://github.com/django-oscar/django-oscar/blob/releases/1.1/src/oscar/apps/catalogue/managers.py#L44-L52" rel="nofollow">
oscar.apps.catalogue.managers</a> and could be customized to provide custom ordering.
This is all assuming you don't want to use a search engine as customizations required to change the order of results for other search handler classes are backend-specific.