Skip to content

Commit 334b296

Browse files
Thadeus Nathanial Burgessmitsuhiko
authored andcommitted
Added documentation for session extensions
1 parent aa7800d commit 334b296

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

flaskext/sqlalchemy.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,30 @@ def create_app():
467467
class User(db.Model):
468468
username = db.Column(db.String(80), unique=True)
469469
pw_hash = db.Column(db.String(80))
470+
471+
You may also define your own SessionExtension instances as well when
472+
defining your SQLAlchemy class instance. You may pass your custom instances
473+
to the `session_extensions` keyword. This can be either a single
474+
SessionExtension instance, or a list of SessionExtension instances. In the
475+
following use case we use the VersionedListener from the SQLAlchemy
476+
versioning examples.::
477+
478+
from history_meta import VersionedMeta, VersionedListener
479+
480+
app = Flask(__name__)
481+
db = SQLAlchemy(app, session_extensions=[VersionedListener()])
482+
483+
class User(db.Model):
484+
__metaclass__ = VersionedMeta
485+
username = db.Column(db.String(80), unique=True)
486+
pw_hash = db.Column(db.String(80))
470487
"""
471488

472-
def __init__(self, app=None, use_native_unicode=True, session_extensions=None):
489+
def __init__(self, app=None, use_native_unicode=True,
490+
session_extensions=None):
473491
self.use_native_unicode = use_native_unicode
474-
self.session_extensions = to_list(session_extensions, []) + [_SignallingSessionExtension()]
492+
self.session_extensions = to_list(session_extensions, []) + \
493+
[_SignallingSessionExtension()]
475494

476495
self.session = _create_scoped_session(self)
477496

0 commit comments

Comments
 (0)