Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added init_app support. #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion flask_peewee/db.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import peewee
from peewee import *

Expand All @@ -6,14 +9,19 @@


class Database(object):
def __init__(self, app):
def __init__(self, app=None):
if app:
self.init_db(app)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init_db?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I pushed to wrong version. Going to create a new pull request for the fixed version.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new method init_app(app) to allow empty instantiation of Database objects:
db = Database(None)
db.init_app(app)
see http://pythonhosted.org/Flask-SQLAlchemy/api.html for details


def init_app(self, app):
self.app = app
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


self.load_database()
self.register_handlers()

self.Model = self.get_model_class()


def load_database(self):
self.database_config = dict(self.app.config['DATABASE'])
try:
Expand Down