Show TimeField value without seconds - Django

Viewed 149

I'm displaying a selectbox with hours in it. This hours are fixed and coming from db. For this I used models.TimeField in models.py. Now in html page these hours are shown like 14:00:00. I want to remove seconds. Here are my codes:

models.py:

class MeetingHour(models.Model):
    hour = models.TimeField()

    def __str__(self):
        return str(self.hour)

html:

<select>
{% for meetinghour in meetinghours %}
  <option value="{{meetinghour}}">{{meetinghour}}</option>
{% endfor %}
</select>
2 Answers

You'll need to format the relevant tag in your template using the time format, so something like this...

<option value="{{meetinghour}}">{{meetinghour|time:"H:i"}}</option>
Related