Skip to content

Instantly share code, notes, and snippets.

View doc-hex's full-sized avatar
💭
Headphones.

doc-hex doc-hex

💭
Headphones.
View GitHub Profile
### Keybase proof
I hereby claim:
* I am peter-conalgo on github.
* I am dochex (https://keybase.io/dochex) on keybase.
* I have a public key whose fingerprint is 4589 779A DFC1 4F33 2753 4EA8 A3A3 1BAD 5A2A 5B10
To claim this, I am signing this object:
@doc-hex
doc-hex / sqlalchemy_getindex
Created March 16, 2014 18:49
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