在下面的模板中,我试图获取法院的名称(通过“机构”字段捕获)。我正在通过avail_times 函数传递“club_id”,但是如何传递通过模板传递的“建立”字段?
该模型:
class Club(models.Model):
establishment = models.CharField(max_length=200)
address = models.CharField(max_length=200)
def __unicode__(self):
return self.establishment
class Available(models.Model):
club = models.ForeignKey(Club)
court = models.CharField(max_length=200)
avail_time = models.DateTimeField('available time')
def __unicode__(self):
return self.court
功能:
def avail_times(request, club_id):
courts = Available.objects.filter(club__id=club_id)
return render_to_response('reserve/templates/avail_times.html', {'courts': courts})
模板:
<h1>All available courts for {{ court.club }}</h1>
<ul>
{% for court in courts %}
<li>{{ court }}</li>
{% endfor %}
</ul>