I have an issue that I have got myself into a mess trying to solve, so any 
help would be appreciated.

I have implemented a simple search solution that works fine and this is my 
view:

from django.shortcuts import render
from django.views.generic import ListView
from jobs.models import Job
from django.db.models import Q
from .filters import JobFilter


class JobListView(ListView):
    model = Job
    paginate_by = 10
    template_name = 'jobs/job_list.html'

    def get_queryset(self):
        queryset = Job.objects.all()
        q = self.request.GET.get("q")
        if q:
            queryset = queryset.filter(
                Q(title__icontains=q) |
                Q(category__category__icontains=q) |
                Q(description__icontains=q)
            ).distinct()
        self.sort_by = self.request.GET.get('sort_by', 'start_date')
        return queryset.order_by(self.sort_by)

    def get_context_data(self,  **kwargs):
        context = super(JobListView, self).get_context_data(**kwargs)
        context['title'] = "Job List"
        context['sort_by'] = self.sort_by
        context['object_name'] = "job_list"
        return context

Everything thing works fine with this. However what I would like to do is 
to allow a person to filter on certain criteria within this page. I have 
created a separate view using django-filters which achieves this but would 
like to combine this. Any suggestions?
Thanks in advance. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3da8cefb-7014-48f9-b323-e5e0745ce6c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to