1

テンプレートの一部の要素を「anno」で注文したいのですが、方法や場所がわかりません(ビューまたはテンプレートからの場合)。|dictsort: を試してみましたが、何かを見逃しているか、何か間違っていると思います。私を手伝ってくれますか...???!!!ありがとう...

私のmodels.py:

class Anno( models.Model ):
    anno = models.CharField( max_length=4 )
    def __unicode__(self):
        return self.anno
    class Meta:
        verbose_name_plural = "Anni"

class Sequel_Film( models.Model ):
    saga = models.CharField( max_length=30 )
    def __unicode__(self):
        return self.saga
    class Meta:
        verbose_name_plural = "Sequels"

class Film( models.Model ):
    titolo = models.CharField( max_length=39 )
    trama = models.TextField( max_length=1000 )
    locandina = models.FilePathField( path="C:/Users/Federico/Google Drive/Umore/apps/Database/static/Film/Locandina", recursive=True )
    copertina = models.FilePathField( path="C:/Users/Federico/Google Drive/Umore/apps/Database/static/Film/Copertina", recursive=True )
    trailer = models.FilePathField( path="C:/Users/Federico/Google Drive/Umore/apps/Database/static/Film/Trailer", recursive=True )
    data_inserimento = models.DateField( null=True, verbose_name="data d'inserimento" )
    anno = models.ForeignKey( Anno )
    durata = models.IntegerField( max_length=5 )
    attori = models.ManyToManyField( Attore )
    registi = models.ManyToManyField( Regista )
    studi = models.ManyToManyField( Studio )
    umori = models.ManyToManyField( Umore )
    generi = models.ManyToManyField( Genere_Film )
    sequels = models.ManyToManyField( Sequel_Film )
    def __unicode__(self):
        return self.titolo + " " + self.trama
    class Meta:
        verbose_name_plural = "Films"

私のviews.py:

def film(request, id):
    film = get_object_or_404( Film, pk=id )
    return render_to_response('Film.html', { 'film': film })

私のテンプレート Film.html :

  {% for sequel in film.sequels.all %}
    {% for film in sequel.film_set.all %}
    {% endfor %}
  {% endfor %}

しかし、テンプレートのタグの間には...

  {% for sequel in film.sequels.all %}
  {% for film in sequel.film_set.all %} #{% for sequel_film in sequel.ordered_film_set %}
  <div class="clear paddingT15">&nbsp;</div>
  <div class="grid_11">
    <div class="grid_9">
      <h3><a class="black hover" href="/Database/Film/{{ film.id }}">{{ film.titolo }}</a></h3>
    </div>
    <div class="grid_2 right">
      <p class="marginB10"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"><img class="h20 w20 marginT-4" src="stella.jpg"></p>
    </div>
    <div class="clear">&nbsp;</div>
    <div class="grid_2 paddingR15">
      <a href="/Database/Film/{{ film.id }}"><img class="w120 h165" src="Eagle-eye.jpg" ></a>
    </div>
    <div class="grid_3">
      <p class="marginB10 bold color">{% for umori in film.umori.all %}{{ umori.umore }}<br>{% endfor %}</p>
    </div>
    <div class="grid_3">
      <p class="marginB10 bold color">{% for generi in film.generi.all %}{{ generi.genere }}<br>{% endfor %}</p>
    </div>
    <div class="grid_1">
      <p class="marginB10 bold color">{{ film.anno }}<br>{{ film.durata }} min.</p>
    </div>
    <div class="grid_2 bordoL2 floatR marginR-30">
      <div class="grid_2 Lheight10">
    <p class="color marginL5 marginB10 size12">Visto:<span class="bold">No</span></p>
      </div>
      <div class="grid_2">
    <p class="color marginL5 marginB10 size12">Umore:<span class="bold"></span></p>
      </div>
      <div class="grid_2">
    <p class="color marginL5 marginT-5 size12">Vota: <img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"><img class="h10 w10" src="nessuno.jpg"></p>
      </div>
    </div>
    <p class="recensione_a">Iauhc iewohafiuhedpidheas wpid wei eiageiweg wiieadfef iuadgqef iupi hi eri haiu reiugsi4fri sireehre efi iviviu rier ef uviu li elu riwf iuh ger iugeiu Iauhc iewohafiuhedpidheas wpid wei eiageiweg wiieadfef iuadgqef iupi hi eri haiu reiugsi4fri sireehre efi iviviu rier ef uviu li elu riwf iuh ger iugeiu</p>
    <div class="clear">&nbsp;</div>
  </div>
  <div class="clear paddingT15">&nbsp;</div>
  {% endfor %}
  {% endfor %}

{{sequel_film}} の使い方 ??? 申し訳ありませんが、わかりません...

4

1 に答える 1

2

モデルにヘルパーを追加できます。

class Sequel_Film( models.Model ):
    ...

    def ordered_film_set(self):
        return self.film_set.all().order_by('anno__anno')

テンプレート内:

{% for sequel in film.sequels.all %}
    {% for sequel_film in sequel.ordered_film_set %}
        {{sequel_film}}
    {% endfor %}
{% endfor %}
于 2013-06-13T14:11:27.487 に答える