I'm using Django==1.11. As I understand from class based views, in this case ListView, you can access url params in get_queryset with self.kwargs, as answered here and here. And I have no problem when I use get_context_data and self.kwargs.
But I can't get it to work in get_queryset. ¿What I'm doing wrong or missing? I've been trying so many alternatives but I can't get the right one.
My code:
urls
urlpatterns = [
url(r'^escuelas/(?P<level>(inicial|primario|secundario))/$', SchoolListView.as_view(), name='school-by-level-index'),
#...
view
class SchoolListView(ListView):
model = School
template_name = 'edu/adminlte/school_index.html'
def get_queryset(self):
queryset = super(SchoolListView, self).get_queryset()
"""
Here below self.kwargs['level'] does not return anything as I would expect
"""
level = self.kwargs['level']
if level is 'inicial':
queryset = School.objects.filter(level='I')
return queryset
return queryset
Thanks.