私は初心者で、愚かな質問かもしれませんので、事前の援助に感謝します。特定の監督が監督した映画のリストをテンプレートで見たいと思います。以下のファイルは、これまでに私が作成したものです。ファイルに修正を加えてください。
ここにmodels.pyがあります:
from django.db import models
class Genere_Film( models.Model ):
genere = models.CharField( max_length=25 )
def __unicode__(self):
return self.genere
class Meta:
verbose_name_plural = "Generi_Film"
class Anno( models.Model ):
anno = models.CharField( max_length=4 )
def __unicode__(self):
return self.anno
class Meta:
verbose_name_plural = "Anno"
class Durata( models.Model ):
durata = models.CharField( max_length=5 )
def __unicode__(self):
return self.durata
class Meta:
verbose_name_plural = "Durata"
class Attore( models.Model ):
nome = models.CharField( max_length=30 )
cognome = models.CharField( max_length=30 )
foto = models.CharField( max_length=100 )
data_inserimento = models.DateField( null=True, verbose_name="data d'inserimento" )
def __unicode__(self):
return self.nome + " " + self.cognome + " " + self.foto
class Meta:
verbose_name_plural = "Attori"
class Regista( models.Model ):
nome = models.CharField( max_length=30 )
cognome = models.CharField( max_length=30 )
foto = models.CharField( max_length=100 )
data_inserimento = models.DateField( null=True, verbose_name="data d'inserimento" )
def __unicode__(self):
return self.nome + " " + self.cognome + " " + self.foto
class Meta:
verbose_name_plural = "Registi"
class Studio( models.Model ):
nome = models.CharField( max_length=30 )
foto = models.CharField( max_length=100 )
data_inserimento = models.DateField( null=True, verbose_name="data d'inserimento" )
def __unicode__(self):
return self.nome #+ " " + self.foto
class Meta:
verbose_name_plural = "Studi"
class Trailer( models.Model ):
trailer = models.CharField( max_length=100 )
data_inserimento = models.DateField( null=True, verbose_name="data d'inserimento" )
def __unicode__(self):
return self.trailer
class Meta:
verbose_name_plural = "Trailers"
class Film( models.Model ):
titolo = models.CharField( max_length=39 )
trama = models.CharField( max_length=1000 )
locandina = models.CharField( max_length=100 )
copertina = models.CharField( max_length=100 )
trailer = models.ForeignKey( Trailer )
data_inserimento = models.DateField( null=True, verbose_name="data d'inserimento" )
anno = models.ForeignKey( Anno )
durata = models.ForeignKey( Durata )
attori = models.ManyToManyField( Attore )
registi = models.ManyToManyField( Regista )
studi = models.ManyToManyField( Studio )
generi = models.ManyToManyField( Genere_Film )
def __unicode__(self):
return self.titolo + " " + self.trama + " " + self.locandina + " " + self.copertina
class Meta:
verbose_name_plural = "Film"
urls.py は次のとおりです。
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^Film$', 'Database.views.film'),
)
これがviews.pyです:
from django.shortcuts import render_to_response
from django.template import RequestContext
from models import *
def film(request):
film = Film.objects.all()
return render_to_response('Film.html', { 'film': film, })
template.html は次のとおりです。
enter code here