0

我想通过“anno”订购“regista”({% for film in regista.film_set.all %})和“sequel”({% for sequel in film.sequels.all %})的“电影”,但我不知道该怎么做......谢谢您的帮助......

这里是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 Film( models.Model ):
    titolo = models.CharField( max_length=39 )
    trama = models.TextField( max_length=1000 )
    anno = models.ForeignKey( Anno )
    registi = models.ManyToManyField( Regista )
    generi = models.ManyToManyField( Genere_Film )
    sequels = models.ManyToManyField( "self", blank=True )
    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

{{ film.titolo }}
{% for generi in film.generi.all %}{{ generi.genere}}{% endfor %}
{{ film.anno }}
{{ film.trama }}
{% for regista in film.registi.all %}
  {{ regista.nome }} {{ regista.cognome }}
  {% for film in regista.film_set.all %}
    {{ film.titolo }}
  {% endfor %}
{% endfor %}
{% for sequel in film.sequels.all %}
  {{ sequel.titolo }}
{% endfor %}
4

1 回答 1

0

在您的class Meta中,您可以指定ordering

class Anno( models.Model ):
    anno = models.CharField( max_length=4 )
    def __unicode__(self):
        return self.anno
    class Meta:
        verbose_name_plural = "Anni"
        ordering = ('anno', )
于 2013-06-14T15:20:21.383 回答