Peewee


  1. Modeling a simple blog post:

from peewee import *

class Post(Model):
    title = CharField()
    body = TextField()
    timestamp = DateTimeField()

    class Meta:
        database = db
  1. Adding a foreign key relationship:

from peewee import *

class User(Model):
    name = CharField()

class Post(Model):
    title = CharField()
    body = TextField()
    timestamp = DateTimeField()
    user = ForeignKeyField(User, backref='posts')

    class Meta:
        database = db
  1. Creating a many-to-many relationship:

  1. Adding a composite key:

  1. Creating a self-referencing relationship:

  1. Adding a database constraint:

  1. Using a custom field type:

  1. Using a custom function:

  1. Creating an aggregate query:

  1. Using a subquery:

  1. Creating a view:

  1. Using a trigger:

  1. Creating a stored procedure:

  1. Using a database adapter:

  1. Using a connection pool:

  1. Using a model manager:

  1. Using a custom validator:

  1. Using a custom hook:

  1. Using a custom loader:

  1. Using a custom writer:

  1. Interacting with a database in a multithreaded environment:

  1. Using a SQLite BLOB field:

  1. Using a PostgreSQL JSON field:

  1. Using a MySQL TEXT field:

  1. Using a Microsoft SQL Server VARCHAR field:

  1. Adding a column to a model:

  1. Dropping a column from a model:

  1. Renaming a column in a model:

  1. Creating a custom Peewee field type:

  1. Using a custom Peewee validator:

  1. Creating a custom Peewee hook:

  1. Creating a custom Peewee loader:

  1. Creating a custom Peewee writer:

  1. Using a Peewee model manager:

  1. Using a Peewee queryset

  1. Using a Peewee subquery:

  1. Using a Peewee aggregation

  1. Using a Peewee raw query

  1. Using a Peewee transaction

  1. Using a Peewee model hook

  1. Using a Peewee validator

  1. Using a Peewee loader

  1. Using a Peewee writer

  1. Using a Peewee manager

  1. Using a Peewee foreign key

  1. Using a Peewee one-to-many relationship

  1. Using a Peewee many-to-many relationship

  1. Using a Peewee composite key

  1. Using a Peewee database constraint

  1. Using a Peewee custom field type

  1. Using a Peewee custom function

  1. Using a Peewee aggregate query

  1. Using a Peewee subquery

  1. Using a Peewee view

5