鉴于以下模型和视图,对于任何给定的俱乐部,我试图在模板中显示该俱乐部的可用球场(“球场”)和可用时间(“avail_time”)。我很难做到这一点。
模型:
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 %}