in models.py
from django.db import models
class TimeItem(models.Model):
WEEKDAYS = [
(0, _("Monday")),
(1, _("Tuesday")),
(2, _("Wednesday")),
(3, _("Thursday")),
(4, _("Friday")),
(5, _("Saturday")),
(6, _("Sunday")),
]
day = models.IntegerField(choices=WEEKDAYS)
hour = models.IntegerField()
def __str__(self):
return self.day
in views.py
from django.shortcuts import render
from .models import TimeItem
def testing(request):
time_items = TimeItem.objects.all()
return render(request, "index.html", {
"time_items": time_items,
})
entered data in django admin
1. day = monday, hour = 1
2. day = monday, hour = 2
3. day = tuesday, hour = 3
The output in the index.html should look like this
Monday:
1
2
Tuesday:
3
my Try in index.html
{% extends "dashboard/base.html" %}
{% load static %}
{% block content %}
{% for time_item in time_items %}
{% if time_item.day == 0 %}
{{ time_item.get_day_display }}
{% endif %}
{{ time_item.hour}} <br>
{% endfor %}
{% endblock %}
The problem I have is that when I start the query as in the index.html, that I am then output the word Monday 2 times. I would like to have there but only 1 time Monday output.