-
How should define field so it will use localtimezone? I'm trying to implement something like: from datetime import timezone
import datetime
class DateFieldsModel(ormar.Model):
class Meta:
abstract = True
created_date: datetime.datetime = ormar.DateTime(
default=datetime.datetime.now(timezone.utc+3), name="creation_date"
)
updated_date: datetime.datetime = ormar.DateTime(
default=datetime.datetime.now(timezone.utc+3), name="modification_date"
) getting:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
When I run the datetime as you wrote it I get an exception. This works for me: from datetime import datetime, timezone, timedelta
check = datetime.now(tz=timezone(timedelta(hours=3)))
print(check) But the error is coming from a statement, which statement? It seams you try to filter by date that has no timezone or something similar? By the way the de facto standard is to keep all the dates either in system timezone (your code server tz) or your database tz (sql server). Most of the systems keep also dates in utc and only convert it to different tzs for presentation, as operations on dates with tzs can be very tricky. If you want system date use Note that you also execute now() so you assign a value, one, same date for all, set at start of your script (use lambda or helper to get a new one each time). |
Beta Was this translation helpful? Give feedback.
-
Have similar problem The model field: On creating an instance, get the exception: Have googled an issue: MagicStack/asyncpg#138 |
Beta Was this translation helpful? Give feedback.
-
Added in 0.10.14 (via #265). |
Beta Was this translation helpful? Give feedback.
Added in 0.10.14 (via #265).
Please update and check.