Wow somebody already brought this to light! http://stackoverflow.com/questions/2768607/dynamic-class-creation-in-sqlalchemy
On Jun 20, 11:36 am, Cody Django <codydja...@gmail.com> wrote: > Hello! > > I would like to dynamically set/change the table that is mapped in my > python object, as instantiated through the declarative style. > > class Feature(Base, GeometryTableMixIn): > """ this is dynamically created to use a table and pk_column > determined at runtime """ > > __table_args__ = { > "schema": 'a_schema', > "autoload": True, > "autoload_with": Session.bind, > "useexisting": True > } > > wkb_geometry = GeometryColumn('wkb_geometry', Geometry(srid=4269)) > > def __init__(self, *args, **kwargs): > self.__tablename__ = kwargs['tablename'] > self.pk_id = Column('%s' % kwargs['pk_id'], types.Integer, > primary_key=True, autoincrement=False) > super(Feature, self).__init__(*args, **kwargs) > > This doesn't work: > > InvalidRequestError: Class <class 'javelin.model.feature.Feature'> > does not have a __table__ or __tablename__ specified and does not > inherit from an existing table-mapped class. > > Could this possibly be done through another approach? Suggestions are > greatly appreciated. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.