Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from datetime import datetime
import pytz
import dateutil.tz
from pynamodb.models import Model
from pynamodb.attributes import NumberAttribute, UTCDateTimeAttribute
class MyModel(Model):
class Meta:
table_name = 'my_model'
read_capacity_units = 10
write_capacity_units = 10
host = "http://localhost:8000"
k = NumberAttribute(hash_key=True)
t = UTCDateTimeAttribute()
MyModel.create_table()
m1 = MyModel()
m1.k = 123
m1.t = datetime.utcnow()
print(m1.t, m1.t.tzinfo)
m1.save()
m2 = MyModel.get(123)
print(m2.t, m2.t.tzinfo)
m2.t = datetime.utcnow().replace(tzinfo=pytz.utc)
m2.save()
m3 = MyModel.get(123)
print(m3.t, m3.t.tzinfo)
m3.t = datetime.now().replace(tzinfo=dateutil.tz.tzlocal())
print(m3.t, m3.t.tzinfo)
m3.save()
m4 = MyModel.get(123)
print(m4.t, m4.t.tzinfo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment