S
S
SilentSokolov2013-04-24 17:04:03
Flask
SilentSokolov, 2013-04-24 17:04:03

Extension for Flask and sqlalchemy?

In general, is it possible to create an extension for the flask ala Django-module, that is, which can fully work with sqlalchemy (create a table, save)?

from flask.ext.blog import Blog()<br>
    blog = blog(app, db_session=session)<br>

The point is that it works from the same session as the rest of the application.

There is another option, create inside the application, and suck in it:

db = SQLAlchemy()<br>
<br>
    User(db.Model):<br>
    __tablename__ = 'users'<br>
    ....<br>

Similar can be seen in this extension.

But then, if I want to create a relationship (relationship) on the model in the extension, I will get an error that the sessions are different and it is impossible to create a relationship.
db = SQLAlchemy() # новый!<br>
<br>
    Group(db.Model):<br>
    __tablename__ = 'groups'<br>
    ....<br>
    users = db.relationship('User') # ошибка мапинга<br>


Ideas?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
ramzes_yan, 2013-04-24
@ramzes_yan

and if db is imported from User?

D
defuz, 2013-04-25
@defuz

What's stopping you from accepting db.sessionyour extension as an argument? And yes, think carefully, you need exactly the extention or blueprint, because the concept of "blog" is more like a blueprint.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question