TimeField presentation format in Django

0
class Passagem(models.Model):
    inscricao = models.ForeignKey(Inscricao, verbose_name='inscricao', related_name='passagem',
                              on_delete=models.CASCADE)
    hora_passagem = models.TimeField('Tempo', auto_now_add=True)

I have this table where I write the hora_passagem , which is of type TimeField . When presenting in the web system, it has the following format: "14:35" .

How do I display it in this format: "14:34:58.943943"

I'm using Django 2.1.

    
asked by anonymous 05.11.2018 / 17:59

1 answer

2

In Django there is the date filter in the template that you can use to format the date:

{% for obj in objs %}
    <h1>{{ obj.hora_passagem|date:'H:i:s:u' }}</h1>
{% endfor %}

This for a template similar to:

from django.db import models

class Passagem(models.Model):
    hora_passagem = models.TimeField()

And a view :

from django.shortcuts import render
from .models import Passagem

# Create your views here.
def home(request):
    objs = Passagem.objects.all()
    return render(request, 'main/index.html', {'objs': objs})

See working at link or the source code at Repl.it .

    
05.11.2018 / 18:03