Move models to a separate file
This commit is contained in:
32
models.py
Normal file
32
models.py
Normal 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')
|
||||
Reference in New Issue
Block a user