tortoise / tortoise/tortoise-orm

TimeField native time format

Open
#1,310 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Describe the bug
TimeField is not in native time format. The TimeField is shown in the table as follows '00:00:04+00'.I just want it to be '00:00:04'.
'use_tz': False, same problem persists.

To Reproduce

from tortoise import Model, fields

SUPPORT_TYPE = (
    (1, 'Payment'),
    (2, 'Free'),
    (3, 'Continuous'),
)

class User(Model):
    id = fields.IntField(pk=True)
    username = fields.CharField(max_length=20, unique=True)
    password = fields.CharField(max_length=128, null=True)
    first_name = fields.CharField(max_length=60, null=True)
    last_name = fields.CharField(max_length=60, null=True)
    email = fields.CharField(max_length=60, unique=True)
    image = fields.CharField(max_length=60, null=True)
    phone = fields.CharField(max_length=30, null=True)
    created_at = fields.DatetimeField(auto_now_add=True)
    updated_at = fields.DatetimeField(auto_now=True)

    def full_name(self) -> str:
        if self.first_name or self.last_name:
            return f"{self.first_name or ''} {self.last_name or ''}".strip()
        return self.username

class Customer(Model):
    id = fields.BigIntField(pk=True)
    code = fields.CharField(max_length=30, null=True)
    name = fields.CharField(max_length=200)
    image = fields.CharField(max_length=60, null=True)
    website = fields.CharField(max_length=120, null=True)
    description = fields.TextField(null=True)

    class Meta:
        ordering = ["name"]

    def __str__(self) -> str:
        return self.name

class Support(Model):
    id = fields.BigIntField(pk=True)
    customer = fields.ForeignKeyField('models.Customer', on_delete=fields.CASCADE)
    user = fields.ForeignKeyField('models.User', on_delete=fields.CASCADE)
    support_type = fields.SmallIntField(choices=SUPPORT_TYPE)
    created_date = fields.DateField(auto_now_add=True)
    created_time = fields.TimeField()
    duration = fields.TimeField()

    class Meta:
        table = 'support'

    def __str__(self) -> str:
        return self.customer.name
from models import User, Support
from sanic import Sanic, response
from tortoise.contrib.sanic import register_tortoise

app = Sanic("WebServer")


@app.get("/support_list")
@app.ext.template("support_list.html")
async def list_support(request):
    objects = await Support.all()
    return {"objects": objects}


register_tortoise(
    app,
    db_url="postgres://postgres:root@localhost:5432/myweb",
    modules={"models": ["models"]},
    generate_schemas=True
)

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=8000, debug=True, auto_reload=True)

Expected behavior
I am using Sanic framework postgresql database with Tortoise-orm.

Additional context
sanic_tortoiseorm

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named. Reproduce the shown TimeField example with PostgreSQL and trace where its value is formatted for the table; done means the displayed value is 00:00:04 rather than 00:00:04+00, with regression coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.