I'v written a help function to auto create a class, and predefined a
__init__ function, and auto assign_mapper to a table metadata:

def assign_class(class_name, table, **kwargs):
    import new
    class_ = new.classobj(class_name, (object,), {})
    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            self.__dict__[key] = value
    class_.__init__ = __init__
    globals()[class_name] = class_
    assign_mapper(class_, table, **kwargs)

May be this will be helpful for someone.

How to use it?

    trans_cata_desc = Table('trans_cata_desc', engine,
        Column('__id__', Integer, primary_key = True),
        Column('style_of_cata', String(1), default=''),
        Column('cata_id', Integer, default=0),
        Column('cata_desc', String(40), default=''),
        redefine = True
        )
    assign_class('TransCataDesc', trans_cata_desc)

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to