Unless I understand you wrong, this should be all you need:

def as_dictionary(self):

        song = {

            "id": self.id,

            "info": self.info.as_dictionary() }

        return song
>


FWIW, I just use a base class / mixin that has this method:

class UtilityObject(object): def columns_as_dict(self): return dict((col.name, 
getattr(self, col.name)) for col in 
sqlalchemy_orm.class_mapper(self.__class__).mapped_table.c) 

this will ONLY handle the defined columns in the class -- it will not 
handle the relationships. You can extend this to handle the relationships 
using another attribute, though I forget what it is. (If you do a 
pdb.set_trace() you can just `dir()` the object to find the properties.)

But that will give you a dictionary on every object... So then going back 
to your example, you could just have `custom_dictionary` that handles the 
columns + a specific relationship 

def custom_dictionary(self):

        song = {

            "id": self.id,

            "info": self.info.columns_as_dict() }

        return song
>


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to