1

私は映画とテレビ番組の両方のデータベースを持っています。これらを次のようにフィルタリングしたい: /productions/ = index (all)、/productions/films/ = 映画のみ、/productions/series/ = テレビ番組のみ

## urls.py
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'),
)

## views.py
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')

このようなことのベストプラクティスは何ですか? それぞれの views.py に新しいメソッドを作成するか、メイン メソッドを再利用して、何らかの方法で URL セグメントを解析して if(productions.is_movie) のようなものを呼び出すことができますか?

4

1 に答える 1