Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Flask-Sqlalchemy monkey patch to simplify debug with: DBObjectClassName[pk_value]
# Hack to allow me to type just ClassName[34] and fetch DB object with pk=34
from flask.ext.sqlalchemy import _BoundDeclarativeMeta
def _get_by_pk(cls, idx):
return cls.get(idx)
_BoundDeclarativeMeta.__getitem__ = _get_by_pk

This comment has been minimized.

Copy link
Owner Author

@peter-conalgo peter-conalgo commented Mar 16, 2014

Actually, that uses a base class function ".get(pk)" that I use on all my objects.

Change line 5 to be "return cls.query.get(idx)" if you don't have that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.