-
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
Shared database and models #103
Comments
To be more specific: the only solution I came up with to date is the following. In models.py, I have this header doing the app-specific import:
This works fine, but is obviously everything but elegant. Any ideas/hints on this? |
Ohhhh... I see your point. I think this has been brought up in connection with flask-sqlalchemy as well. You could always just write your models as regular models -- the only thing the flask-peewee database wrapper really does for you is:
You could even do this: db = Database(app)
# subclass regular peewee.Model
class BaseModel(Model):
class Meta:
database = db.database
# Now you can subclass BaseModel and use those models anywhere. |
Sorry for late reply. Our current project is running fine with the hack I described earlier, so it's not urgent to fix it. Nevertheless, I spotted the activity on #69 and I think that they are related. It would be great if we could find a way to do configuration independent of a given app, and independent of the usage of flask at all (i.e., only use the peewee models in a separate non-web app). |
Reading database URI from abstract config instead of hardcoding config setting name in method; think about creating BaseModel&Metaclass instead of sharing db and using separate model for it -> coleifer/flask-peewee#103
I am not sure if this is the right place to ask as it's more of a "best practice" question. Please point me in the right direction if I should go ask somewhere else.
In a given project, there might be multiple apps that use the same data model. For example, the admin interface, the actual flask application, and some helper scripts. Ideally, they should share the same peewee models. This works fine if the database is configured and set within the models.py.
This clashes though with the flask way of doing things. More specifically, flask-peewee requires me to use the database wrapper, something that can't be used in a non-flask application.
Furthermore, in order to avoid circular inputs, an approach like this is required: http://charlesleifer.com/blog/structuring-flask-apps-a-how-to-for-those-coming-from-django/ , which is again incompatible with shared models.
What is the best practice to share the same peewee models across multiple apps/programs?
The text was updated successfully, but these errors were encountered: