Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using django-haystack, how do I order results by content type

I'm using django-haystack for a search page on my site, and I want to order all the results by their content type. Is there a way I can do that? To make it simpler, suppose I have a single application and several classes. Thanks in advance

like image 847
Yasel Avatar asked Dec 28 '22 23:12

Yasel


1 Answers

Not sure what you mean by content type, but if you are talking about group by models, I have this working

        {% with page.object_list as results %}
            {% regroup results|dictsort:"verbose_name_plural" by verbose_name_plural as grouped_objects %}
            {% for ct in grouped_objects %}
                {{ ct.grouper }}
                {% for result in ct.list %}
                    <p>
                        <a href="{{ result.object.get_absolute_url }}">{{ result.object }}</a>
                    </p>
                {% endfor %}
            {% empty %}
                <p>No results found.</p>
            {% endfor %}
        {% endwith %}
like image 78
James Lin Avatar answered Feb 13 '23 23:02

James Lin