鑑於以下模型和觀點,對於任何給定的俱樂部,我都試圖在模板中展示該俱樂部的可用法院(「法庭」)和可用時間(「avail_time」)。這樣做有困難。在Django的模板中顯示數據的最佳方式是什麼?
型號:
from django.db import models
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
class Taken(models.Model):
club = models.ForeignKey(Club)
court = models.ForeignKey(Available)
taken_time = models.DateTimeField('taken time')
userid = models.EmailField(max_length = 75)
查看:
def avail_times(request, club_id):
p = get_object_or_404(Club,pk=club_id)
return render_to_response('reserve/templates/avail_times.html', {'club':p})
模板:
{% for court in club.court_set.all %}
{{court.court }}
{% endfor %}