You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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?
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
Expected behavior
I am using Sanic framework postgresql database with Tortoise-orm.
Additional context
The text was updated successfully, but these errors were encountered: