33 lines
891 B
Python
33 lines
891 B
Python
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')
|