Filter content by url segments

By : SLekvak

I have a database of both movies and tv shows. I want to filter these like so: /productions/ = index (all), /productions/films/ = only films, and /productions/series/ = only tv shows

from django.conf.urls import patterns, url

from productions import views

urlpatterns = patterns('',
    url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^films/$', views.IndexView.as_view(), name='films'),
    url(r'^series/$', views.IndexView.as_view(), name='series'),

from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.views import generic

from productions.models import Production, Director

class IndexView(generic.ListView):
    template_name = 'productions/index.html'
    context_object_name = 'productions_list'

    def get_queryset(self):
        return Production.objects.order_by('-release')

What would be the best practice for something like this? Create a new method in for each, or could I reuse the main method, and call something like if(productions.is_movie) by somehow parsing the URL segments?

By : SLekvak


I'd capture the string from url, like this:

urlpatterns = patterns('',
By : alecxe

This video can help you solving your question :)
By: admin