I also had this issue and searched around for an answer, but found
nothing. In my case I;m using the orm and wanted to have those object
properties that map to a table be wrapped up in a dict. The new SQLA
book is enroute and I figured I'd look in there when I get it, but in
the mean time I just added a cheap/crude method for conversion as per
below.
import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base
_ORM_BASE = declarative_base()
class _BaseORMMixin():
def ToDict(self, ExclusionList = []):
"""Converts fields in object to a dict, unless field names are
in ExclusionList."""
ret = {}
for c in self.__mapper__.columns.keys():
if not c in ExclusionList:
ret[c] = getattr(self, c)
return ret
class ORM_User(_BaseORMMixin, _ORM_BASE):
__tablename__ = "user"
<snip>
I figure there must be a better way.. I had to dip into __mapper__,
which didn't seem right, but __dict__ obviously has more than what I
wanted. In addition, I had to use a mixin because with
ext.declaritive (which I like because it is less verbose) I couldn't
make a base class to derive from because it complained that I needed
__tablename__ in the base class.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---