-
Notifications
You must be signed in to change notification settings - Fork 178
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
base: master
Are you sure you want to change the base?
Conversation
def __init__(self, app): | ||
def __init__(self, app=None): | ||
if app: | ||
self.init_db(app) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
init_db
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Just ran in to this issue today. I would love to see this become part of flask-peewee. |
+1 |
1 similar comment
+1 |
This is a must for any Flask extension, this needs to be in the master |
+1 |
1 similar comment
+1 |
I didn't see the issue, so I made my own version. I would love to see this patch accepted, not just for Database, but also for Admin and Auth. https://github.com/Ppjet6/flask-peewee/tree/init_app |
This allows you to defer This would need coupling with a change to use |
Agree with @ketralnis. It should work unless you initialize db after your models (raise AttributeError while accessing db.Model) and may be used only as a workaround. |
@ketralnis, you're right. I did rewrite it with peewee.Proxy, and it works nicely. |
it can be extremely useful to initialize an empty Database and add the app in a different file.
currently it is not possible but with this fix it's possible to call
db = flask.ext.peewee.db.Database(None)
and later do
db.init_app(app)