def test_option_inheritance(self): test_db = peewee.Database(SqliteAdapter(), 'testing.db') child2_db = peewee.Database(SqliteAdapter(), 'child2.db') class ParentModel(peewee.Model): title = peewee.CharField() class Meta: database = test_db class ChildModel(ParentModel): pass class ChildModel2(ParentModel): class Meta: database = child2_db class GrandChildModel(ChildModel): pass class GrandChildModel2(ChildModel2): pass self.assertEqual(ParentModel._meta.database.database, 'testing.db') self.assertEqual(ParentModel._meta.model_class, ParentModel) self.assertEqual(ChildModel._meta.database.database, 'testing.db') self.assertEqual(ChildModel._meta.model_class, ChildModel) self.assertEqual(ChildModel2._meta.database.database, 'child2.db') self.assertEqual(ChildModel2._meta.model_class, ChildModel2) self.assertEqual(GrandChildModel._meta.database.database, 'testing.db') self.assertEqual(GrandChildModel._meta.model_class, GrandChildModel) self.assertEqual(GrandChildModel2._meta.database.database, 'child2.db') self.assertEqual(GrandChildModel2._meta.model_class, GrandChildModel2)
import peewee test_db = peewee.Database(peewee.SqliteAdapter(), 'test_pw.db') class User(peewee.Model): username = peewee.CharField() active = peewee.BooleanField(default=False) class Meta: database = test_db class Blog(peewee.Model): user = peewee.ForeignKeyField(User) name = peewee.CharField() class Meta: database = test_db class Entry(peewee.Model): blog = peewee.ForeignKeyField(Blog) title = peewee.CharField() content = peewee.TextField(default='') pub_date = peewee.DateTimeField(null=True) class Meta: database = test_db
#coding: utf-8 import peewee from . import app from members import * database = peewee.Database(peewee.SqliteAdapter(), app.config['DATABASE_NAME']) class BlogEntry(peewee.Model): title = peewee.CharField() eid = peewee.CharField() link = peewee.CharField() author_email = peewee.CharField() summary = peewee.TextField() tags = peewee.CharField() content = peewee.TextField() date = peewee.DateTimeField() updated = peewee.DateTimeField() class Meta: database = database @property def author(self): return Members().by_email(self.author_email)
#!/usr/bin/env python import sys import hashlib import cyclone.web import peewee from twisted.python import log from twisted.internet import defer, reactor database = peewee.Database(peewee.SqliteAdapter(), 'BlueBell.db') class Webuser(peewee.Model): id = peewee.PrimaryKeyField() username = peewee.CharField() salt = peewee.CharField() pwhash = peewee.CharField() class Meta: db_table = 'webusers' database = database class BaseHandler(cyclone.web.RequestHandler): def get_current_user(self): return self.get_secure_cookie("user") class MainHandler(BaseHandler): @cyclone.web.authenticated def get(self):
import peewee from peewee import (SelectQuery, InsertQuery, UpdateQuery, DeleteQuery, Node, Q, database, parseq, SqliteAdapter, PostgresqlAdapter) class QueryLogHandler(logging.Handler): def __init__(self, *args, **kwargs): self.queries = [] logging.Handler.__init__(self, *args, **kwargs) def emit(self, record): self.queries.append(record) test_db = peewee.Database(SqliteAdapter(), 'tmp.db') class TestModel(peewee.Model): class Meta: database = test_db # test models class Blog(TestModel): title = peewee.CharField() def __unicode__(self): return self.title
import peewee from flask import Flask, request, session, g, redirect, url_for, \ abort, render_template, flash from functools import wraps from hashlib import md5 # config DATABASE = 'tweepee.db' DEBUG = True SECRET_KEY = 'hin6bab8ge25*r=x&+5$0kn=-#log$pt^#@vrqjld!^2ci@g*b' app = Flask(__name__) app.config.from_object(__name__) database = peewee.Database(peewee.SqliteAdapter(), DATABASE) # model definitions class User(peewee.Model): username = peewee.CharField() password = peewee.CharField() email = peewee.CharField() join_date = peewee.DateTimeField() class Meta: database = database def following(self): return User.select().join( Relationship,