-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
35 lines (23 loc) · 883 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import datetime as dt
import os
import traceback
import peewee
PATH_TO_DB = os.path.join(os.path.dirname(__file__), 'database.db')
sqlite_db = peewee.SqliteDatabase(PATH_TO_DB)
class BaseModel(peewee.Model):
class Meta:
database = sqlite_db
created_at = peewee.DateTimeField(default=dt.datetime.now())
updated_at = peewee.DateTimeField(default=dt.datetime.now())
def save(self, *args, **kwargs):
self.updated_at = dt.datetime.now()
return super(BaseModel, self).save(*args, **kwargs)
class Config(BaseModel):
api_key = peewee.CharField(unique=True)
api_secret = peewee.CharField(unique=True)
response_language = peewee.CharField(default='ru')
max_notes = peewee.IntegerField(default=10)
try:
sqlite_db.create_tables([Config])
except Exception as e:
traceback.print_exc(e)