from peewee import *
import datetime
db = SqliteDatabase('test_db.db')
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
class BaseModel(Model):
id = PrimaryKeyField(column_name='User ID', unique=True)
user_name = CharField(column_name='Nickname', null=True)
first_name = CharField(column_name='First Name', null=True)
class Meta:
database = db
class User(BaseModel):
telegram_id = PrimaryKeyField(column_name='Telegram ID')
last_name = CharField(column_name='Last Name', null=True)
date_time_join = DateTimeField(column_name='Date time join', default=now)
class Meta:
db_table = 'users'
class Message(BaseModel):
message_id = PrimaryKeyField(column_name='Message ID', unique=True)
message_text = CharField(column_name='Text', null=False)
date_time_add = DateTimeField(column_name='Date time add', default=now)
class Meta:
db_table = 'messages'
# Создание таблиц
db.create_tables([User, Message])