import datetime
from peewee import *
from playhouse.fields import ManyToManyField

db = SqliteDatabase('quotes.db')

class BaseModel(Model):
    class Meta:
        database = db

class Person(BaseModel):
    pass

class Nickname(BaseModel):
    person = ForeignKeyField(Person, related_name="nicks")
    name = TextField(unique=True)

class Category(BaseModel):
    name = TextField(unique=True)

class Quote(BaseModel):
    person = ForeignKeyField(Person, related_name="quotes")
    categories = ManyToManyField(Category, related_name="quotes")
    content = TextField(unique=True)
    date = DateTimeField(default=datetime.datetime.utcnow)
    link_cat = ForeignKeyField(Category, related_name="quotes", null=True)

if __name__ == "__main__":
    db.connect()
    db.create_tables([Person, Nickname, Category, Quote])
    db.commit()
    db.close()
