Given the below model and view, for any given club I am trying to display that club’s available courts (“court”) and available times (“avail_time”) in the template. I am having trouble doing this.
Model:
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)
View:
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})
Template:
{% for court in club.court_set.all %}
{{court.court }}
{% endfor %}
Well, you don’t seem to have a Court model, so I’m not sure why you’re trying to call
court_set.all. You could useclub.available_set.allto show the list of Available instances for that club, which might be what you mean.