Last active
August 29, 2015 14:05
Revisions
-
blurrcat revised this gist
Aug 24, 2014 . 3 changed files with 12 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,7 @@ from flask import Flask from db import db def create_app(config_obj) app = Flask('tets') app.config.fromobj(config_obj) # db configured in `config_obj` db.init_app(app) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ from flask_peewee.db import Database from peewee import Model @@ -23,3 +21,6 @@ class Meta: database = self.database self.Model.Meta = Meta db = DeferredDatabase() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,9 @@ # database engine irrelevant model definitions # i.e., you can define models before connecting to the database from db import db class User(db.Model): class Meta: db_table = 'test_user' name = CharField() -
blurrcat created this gist
Aug 24, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ from flask import Flask from models import Base app = Flask('tets') This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from flask_peewee.db import Database from peewee import Model class DeferredDatabase(Database): def __init__(self, app=None): if app: super(DeferredDatabase, self).__init__(app) else: class BaseModel(Model): pass self.Model = BaseModel def init_app(self, app): self.app = app self.load_database() self.register_handlers() class Meta: database = self.database self.Model.Meta = Meta This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # database irrelevant model definitions class User(Base): class Meta: db_table = 'test_user' name = CharField()