Move models to a separate file

This commit is contained in:
2021-06-03 00:31:22 +02:00
parent e603288bf2
commit 7e81ea0b74
3 changed files with 42 additions and 34 deletions

32
models.py Normal file
View File

@@ -0,0 +1,32 @@
from config import conf
from peewee import MySQLDatabase
from peewee import Model
from peewee import AutoField, CharField, DateTimeField, ForeignKeyField
from peewee import DoesNotExist
db = MySQLDatabase(conf['mysql'].get('database'),
user=conf['mysql'].get('user'),
password=conf['mysql'].get('password'),
host=conf['mysql'].get('host', 'localhost'),
port=conf['mysql'].getint('port', 3306))
class BaseModel(Model):
class Meta:
database = db
class Song(BaseModel):
id = AutoField()
artist = CharField(default='')
title = CharField(default='')
class Meta:
indexes = (
(('artist', 'title'), True), # Unique on artist + title
)
class AirCast(BaseModel):
id = AutoField()
date = DateTimeField()
song = ForeignKeyField(Song, backref='dates')