只有创造,才是真正的享受,只有拚搏,才是充实的生活。
模型定义,生成数据库
from datetime import date
from peewee import *
db = SqliteDatabase('people.db')
'''模型定义'''
class Person(Model):
name = CharField()
birthday = DateField()
is_relative = BooleanField()
class Meta:
database = db
class Pet(Model):
owner = ForeignKeyField(Person, related_name='pets')
name = CharField()
animal_type = CharField()
class Meta:
database = db
"""连接数据库"""
db.connect()
"""创建Person和Pet表"""
db.create_tables([Person, Pet])
uncle_bob = Person(name='Bob', birthday=date(1960, 1, 15), is_relative=True)
uncle_bob.save()
"""连接数据库关闭"""
db.close()