12
In the template below, I am trying to get the name of the court (that is captured through the "establishment" field). I am passing "club_id" through the avail_times function, but how do I pass the "establishment" field passed through the template from this?
The model:
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
The function:
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})
The template:
<h1>All available courts for {{ court.club }}</h1>
<ul>
{% for court in courts %}
<li>{{ court }}</li>
{% endfor %}
</ul>