class Picture(models.Model):
title = models.CharField(max_length=255)
class PictureRate(models.Model):
user = models.ForeignKey(User)
picture = models.ForeignKey(Picture)
rate = models.DecimalField(max_digits=2,decimal_places=1)
意见:
def index(request):
pictures = Picture.objects.all()
return render_to_response('index.html',{'pictures':pictures}, context_instance=RequestContext(request))
在模板中:
{% for p in pictures %}
{{ p.title }}
{% endfor %}
如何在模板计数中显示rate
每个评级()Picture
?