flask-peewee icon indicating copy to clipboard operation
flask-peewee copied to clipboard

added init_app support.

Open crvcrv opened this issue 11 years ago • 10 comments

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)

crvcrv avatar Jan 30 '14 04:01 crvcrv

Just ran in to this issue today. I would love to see this become part of flask-peewee.

timster avatar Apr 02 '14 18:04 timster

+1

AlJohri avatar Apr 04 '14 00:04 AlJohri

+1

svenstaro avatar Apr 20 '14 00:04 svenstaro

This is a must for any Flask extension, this needs to be in the master

JoeLanglois avatar Apr 23 '14 23:04 JoeLanglois

+1

xtao avatar May 03 '14 14:05 xtao

+1

irachex avatar Jul 04 '14 14:07 irachex

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.

Ppjet6 avatar Aug 17 '14 17:08 Ppjet6

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

ketralnis avatar Sep 15 '14 21:09 ketralnis

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.

RealJTG avatar Sep 17 '14 09:09 RealJTG

@ketralnis, you're right. I did rewrite it with peewee.Proxy, and it works nicely. I made a new pull request (#154)

Ppjet6 avatar Sep 18 '14 02:09 Ppjet6