Django将数据显示到有限行的HTML表中

时间:2015-02-28 16:02:15

标签: html django

我有一个表单,有人可以为每月活动注册一些插槽。我想在html表中显示这些数据,以便其他用户知道该事件剩余多少个插槽。如何将数据放入表中,如果上面的那些插槽已经填满,那么它是否填充了下一组插槽?

我的观点是拉出有人要求的插槽数量(pipette_number):

def AM_reservation(request, year, month, change=None):
     year, month = int(year), int(month)

     AM_pipettes = Entry.objects.filter(pipette_number, Time=Morning, date__year=year, date__month=month)
     AM = Time(Morning)
     AM_slots = [0,17]

    for AM_pipettes in AM_slots:
        entries = current = False
        if AM_pipettes:
            entries = Entry.objects.filter(pipette_number, Time=Morning, date__year=year, date__month=month)
            if year == nyear and month == nmonth:
                current = True

注意每个事件有18个插槽。我是否需要将这些放入列表并用数字标记每个插槽?

这是我在html中的for循环:

{% for AM_pipettes in AM_slot %}
    <tr>

            <td class= {% if AM_pipettes == 0 %}"empty"{% endif %}
            {% if AM_pipettes != 0 and not current %}"AM_slot"
            {% endif %} >

            {% if AM_slot != 0 %}
                {{ AM_slot }}
                {% for entry in entries %}
                    <br />
                    <b>{{ entry.creator }}</b>: {{ entry.short|safe }}
                {% endfor %}
            {% endif %}
    </tr>
    {% endfor %}

--- ---更新 时间选择的Model.py代码:

Time_Choices = (
        (Morning, 'AM'), (Afternoon, 'PM'))
 Time = models.CharField(max_length=20,
                                  choices= Time_Choices,
                                  default=Morning)

0 个答案:

没有答案