using filters with django-endless-pagination -
i'm using django endles-pagination load pages in infinite scroll. have filters filter data according criteria (for eg, price slider filtering according price). when page loads, filter right filters page loaded, though want filter pages have been or loaded. there way (by making ajax request or something)?
any on great. lot.
to filter data have redefine get_queryset()
method in views requesting filtered query.
for example request current language in template filter blog posts based on language:
class blog(ajaxlistview): context_object_name = "posts" template_name = 'cgapp/blog.html' page_template = 'cgapp/post_list.html' def get_queryset(self): if self.request.language_code == 'en': #request value of current language return news.objects.filter(language='en') #return filtered object if current language english else: return news.objects.filter(language='uk')
to filter queryset based on users input, may refer post method:
from app.forms import blogfilterform class blog(loginrequiredmixin, ajaxlistview): context_object_name = "posts" template_name = 'blog/blog.html' page_template = 'blog/post_list.html' success_url = '/blog' def get_queryset(self): # define queryset queryset = post.objects.all() # default queryset if self.request.method == 'post': # check if request method post form = blogfilterform(self.request.post) # define form if form.is_valid(): name = form.cleaned_data['name'] # retrieve data form if name: queryset = queryset.filter(name=name) # filter queryset else: queryset = queryset return queryset def get_context_data(self, **kwargs): context = super(blog, self).get_context_data(**kwargs) context['form'] = blogfilterform() # define context render form on method return context def post(self, request, *args, **kwargs): # define post method return super(blog, self).get(request, args, kwargs)
the endless pagination should work fine.