wind4869
6/17/2018 - 12:32 PM

peewee

from peewee import *

mysql_db = MySQLDatabase(
    'test',
    host='localhost',
    port=3306,
    user='root',
    passwd=''
)

mysql_db.connect()


class MySQLModel(Model):
    class Meta:
        database = mysql_db


class Person(MySQLModel):
    name = CharField()
    birthday = DateField()
    is_relative = BooleanField()


class Pet(MySQLModel):
    owner = ForeignKeyField(Person, related_name='pets')
    name = CharField()
    animal_type = CharField()


if __name__ == '__main__':
    # mysql_db.create_tables([Person, Pet])
    pass