python - dynamic modification of foreign keys sqlalchemy -


i'm creating structure of "elements" dynamically declarative, , i'm not sure if can modify mapper new elements related fk. sorry english, poor.

def nuevoelemento(self,nombre_elemento,pos_jerarquia=0,elem_anterior_jerarquia=none):      elemento = nombre_elemento.lower().strip()     nombre_elemento = "elementos_" + elemento     dicc = {'__tablename__':nombre_elemento}      id = column(integer,primary_key=true)     dicc.update({'id':id})     tipo = column(text)     dicc.update({'tipo':tipo})     timestamp = column(text)     dicc.update({'timestamp':timestamp})     eid = column(text)     dicc.update({'eid':eid})     #baja = relationship();dicc.update({'baja':baja})      if pos_jerarquia > 0: ## no es raiz         padre = column(text, foreignkey('elementos_' + elem_anterior_jerarquia + '.id'))         dicc.update({'padre':padre})         sube =  relationship('elementos_' + elem_anterior_jerarquia,backref='elementos_' +nombre_elemento);dicc.update({'sube':sube})#'baja':relationship(tests,backref='tabla_lotes')     etiquetas = relationship('etiquetas_'+elemento,backref='etiquetas_'+elemento)     dicc.update({'etiquetas':etiquetas})      def __init__(self):         self.timestamp = datetime.datetime.now().isoformat('-')         self.tipo = self.__class__.__name__.split('_')[1]         self.eid = self.timestamp + "#" + self.tipo     dicc.update({'__init__':__init__})      def __repr__(self):         return "elemento %s -> eid: %s ->creado %s",         % (self.tipo,self.eid,self.timestamp)     dicc.update({'__repr__':__repr__})      clase_elemento = type(str(nombre_elemento),(base,),dicc)     self.elementos_map.update({nombre_elemento:clase_elemento}) 

now, when create new class, parent redefine fk point new created class, i'm trying session's mapper no success...


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -