tentatively add list command
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
29
bot/commands/list/models.py
Normal file
29
bot/commands/list/models.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from peewee import *
|
||||
import json
|
||||
|
||||
db = DatabaseProxy()
|
||||
|
||||
class BaseModel(Model):
|
||||
class Meta:
|
||||
database = db
|
||||
db_table = 'journal'
|
||||
|
||||
class ListModel(BaseModel):
|
||||
name = CharField(unique=True)
|
||||
content = TextField(default="") # unlimited length, use to serialise list into
|
||||
|
||||
@property
|
||||
def content_list(self):
|
||||
return json.loads(self.content or '[]')
|
||||
|
||||
@content_list.setter
|
||||
def content_list(self, list_content):
|
||||
self.content = json.dumps(list_content)
|
||||
self.save()
|
||||
|
||||
|
||||
|
||||
def set_db(db_path):
|
||||
db.initialize(SqliteDatabase(db_path))
|
||||
db.connect()
|
||||
db.create_tables([ListModel], safe=True)
|
Reference in New Issue
Block a user