I am using class based views in my app but I am stuck at one point. I am using ListView and created two classes which are sub-classes of ListView.
views.py
class blog_home(ListView):
paginate_by = 3
model= Blog
context_object_name = 'blog_title'
template_name = 'blog.html'
class blog_search(ListView):
paginate_by = 4
context_object_name = 'blog_search'
template = 'blog_search.html'
def get_queryset(self):
self.search_result = Blog.objects.filter(title__contains = 'Static')
return self.search_result
urls.py
urlpatterns = [
url(r'^$', index, name='index'),
url(r'^grappelli/', include('grappelli.urls')),
url(r'^blog/', blog_home.as_view(), name='blog_home'),
url(r'^admin/', include(admin.site.urls)),
url(r'^blog/search/',blog_search.as_view(),name='blog_search'),
]
In my above code in blog_Search(), get_queryset() method is not getting called. I mean it's not working. If I use same same method in blog_home it does work.
blog_search not filtering. I added print statement also but not get called.
Can I create two classes with ListView in same file? Is this the problem?
model = Blogin the second one?blog_searchurl is never reached becauseblog_homeis matched first for all urls starting withblog/...you need to fix your urls.py