suchwow/suchwow/models.py

79 lines
2.0 KiB
Python
Raw Normal View History

2020-07-15 09:18:13 +01:00
from peewee import *
from datetime import datetime
from suchwow import config
2020-07-15 09:18:13 +01:00
2020-08-10 07:59:45 +01:00
db = SqliteDatabase(f"{config.DATA_FOLDER}/db/sqlite.db")
2020-07-15 09:18:13 +01:00
2020-07-28 21:31:07 +01:00
class Post(Model):
2020-07-15 09:18:13 +01:00
id = AutoField()
title = CharField()
text = CharField()
2020-07-15 09:18:13 +01:00
submitter = CharField()
image_name = CharField()
2020-07-28 21:31:07 +01:00
readonly = BooleanField(default=False)
hidden = BooleanField(default=False)
account_index = IntegerField()
address_index = IntegerField()
timestamp = DateTimeField(default=datetime.now)
reddit_url = CharField(null=True)
2020-10-18 05:39:19 +01:00
to_reddit = BooleanField(default=False)
2020-10-29 08:13:02 +00:00
to_discord = BooleanField(default=False)
approved = BooleanField(default=False)
2020-12-29 20:41:10 +00:00
def show(self):
return {
'id': self.id,
'title': self.title,
'text': self.text,
'submitter': self.submitter,
'image_name': self.image_name,
'readonly': self.readonly,
'hidden': self.hidden,
'account_index': self.account_index,
'address_index': self.address_index,
'timestamp': self.timestamp,
'reddit_url': self.reddit_url,
'to_reddit': self.to_reddit,
'to_discord': self.to_discord,
'approved': self.approved,
}
class Meta:
database = db
class Moderator(Model):
id = AutoField()
username = CharField(unique=True)
2020-07-28 21:31:07 +01:00
class Meta:
database = db
class Profile(Model):
id = AutoField()
username = CharField()
address = CharField()
2020-08-10 07:59:45 +01:00
notifications = IntegerField(default=0)
2020-07-28 21:31:07 +01:00
class Meta:
database = db
class Comment(Model):
id = AutoField()
comment = TextField()
2020-08-10 07:59:45 +01:00
commenter = ForeignKeyField(Profile)
post = ForeignKeyField(Post)
2020-07-28 21:31:07 +01:00
timestamp = DateTimeField(default=datetime.now)
class Meta:
database = db
class Notification(Model):
type = CharField()
message = TextField()
2020-08-10 07:59:45 +01:00
username = ForeignKeyField(Profile)
2020-07-15 09:18:13 +01:00
timestamp = DateTimeField(default=datetime.now)
class Meta:
database = db