def avail_times(request, club_id):
club = get_object_or_404(Club,pk=club_id)
open_slots = Opening.objects.filter(club_id=club_id, day=datetime.date.today(), reservation = Open )
return render_to_response( reserve/templates/avail_times.html , { club :club, open_slots :open_slots})
<ul>
{% for slot in open_slots %}
<li> {{slot }} on Court {{slot.court}} </li>
{% endfor %}
</ul>
from django.db import models
import datetime
class Club(models.Model):
establishment = models.CharField(max_length=200)
address = models.CharField(max_length=200)
def __unicode__(self):
return self.establishment
class Day(models.Model):
club = models.ForeignKey(Club)
day = models.DateField( day )
def __unicode__(self):
return unicode(self.day)
class Court(models.Model):
club = models.ForeignKey(Club)
day = models.ForeignKey(Day)
court = models.IntegerField(max_length=200)
def __unicode__(self):
return unicode(self.court)
class Opening(models.Model):
club = models.ForeignKey(Club)
day = models.DateField( date )
court = models.ForeignKey(Court)
slot = models.TimeField( slot )
reservation = models.CharField(max_length=200)
def __unicode__(self):
return unicode(self.slot)
在以上模板中,我只想显示一个独特的“位置”时间。 因此,即便在“法院1”和“法院2”两个项目下出现6am,我也希望通过模板只显示一次。 我如何这样做?