flask-peewee
flask-peewee copied to clipboard
added init_app support.
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)
Just ran in to this issue today. I would love to see this become part of flask-peewee.
+1
+1
This is a must for any Flask extension, this needs to be in the master
+1
+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 The thing with Admin and Auth is that I had to change the signatures. As I don't want to break everything I'm not requesting yet, I'll wait for someone with a better Idea.
This allows you to defer init_app
but it doesn't actually give you separate state per application, since most of that state in peewee happens at import time (defined in the Meta
child class). Importantly, one of the reasons that you want the factory pattern is so that you can override config settings in your unit tests, but this won't allow you to do that.
This would need coupling with a change to use peewee.Proxy
for database initialisation
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. I made a new pull request (#154)