1
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)

在上面的模板中,我只想显示一个不同的“插槽”时间。因此,即使早上 6 点出现在“法院 1”和“法院 2”下,我也希望它只通过模板显示一次。我该怎么做?

4

1 回答 1

6

内置regroup过滤器正是这样做的。

于 2012-05-22T05:57:19.443 回答