jieter / django-tables2

django-tables2 - An app for creating HTML tables
https://django-tables2.readthedocs.io/en/latest/
Other
1.87k stars 426 forks source link

Haystack Example #642

Open AndreGuerra123 opened 5 years ago

AndreGuerra123 commented 5 years ago

Hello, Similarly to the provided example with 'django_filters' package for filtering the data, would it be possible to include an example using Haystack since from the available pull requests it seems integration is feasible. Best regards,

jieter commented 5 years ago

You are welcome to contribute to the docs, I am not a haystack user myself, so I am not able to effectively create the example.

AndreGuerra123 commented 5 years ago

There is little information online specially using CBVs. I found someone that implemented it successfully I will get in touch soon, since I honestly think will be a great addition to see the integration of these two amazing packages.

Asday commented 5 years ago

@AndreGuerra123 Would you be able to provide a link to the example to which you're referring? I had a quick look around and was unable to find it.

jmb commented 4 years ago

I've got this working, but not sure if it's the right solution or a bit hacky...

from haystack.generic_views import SearchView
import django_tables2
from .tables import SearchTable

class MySearchView(django_tables2.SingleTableMixin, SearchView):
    table_class = SearchTable
    template_name = "search/mytemplate.html"

    def get_table_data(self):
        return [result.object for result in self.queryset]