Skip to content

Instantly share code, notes, and snippets.

@richard24se
Last active August 26, 2019 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richard24se/e3c5b6fc6796bf121b96eda7e43777c3 to your computer and use it in GitHub Desktop.
Save richard24se/e3c5b6fc6796bf121b96eda7e43777c3 to your computer and use it in GitHub Desktop.
getFieldsSQLAlchemy.py
#METHOD TO GET FIELDS FROM MODEL
def get_fields_sqlalch(self,cols,model):
return [model.__dict__[k] for k in cols]
#USE METHOD
fields = get_fields_sqlalch(['campo1','campo2'],ColaboradorModel)
#APPLY FIELDS TO QUERY
result = [o._asdict() for o in s.query(*fields)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment