Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeField native time format #1310

Open
ystekno opened this issue Dec 27, 2022 · 1 comment
Open

TimeField native time format #1310

ystekno opened this issue Dec 27, 2022 · 1 comment

Comments

@ystekno
Copy link

ystekno commented Dec 27, 2022

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

@uxhao-o
Copy link

uxhao-o commented Jan 31, 2023

I also met this problem.
Anyone know how to deal with this problem?
If I want to use date format string like "%Y-%m-%d %H:%M:%S" in DateTimeField for generating date format that I wish, how do I?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants