Re: [sqlalchemy] Not loading a kind of elements

2011-02-02 Thread slothy Rulez a lot
It's working!!!, thanks!

2011/2/1 Michael Bayer mike...@zzzcomputing.com

 The query itself has to not load the row in the first place.  There's a
 recipe for that here:

 http://www.sqlalchemy.org/trac/wiki/UsageRecipes/PreFilteredQuery


 On Feb 1, 2011, at 11:46 AM, slothy Rulez a lot wrote:

 Hi, list!

 I'm trying, to discriminate certain type of rows in the database, in a
 table with various attributes, if one attribute, ej: active =
 Column(Boolean) is set to False, I don't want it to appear in any kind of
 query, but still present in the DB.

 My first attempt is define a reconstructor like this:

 @orm.reconstructor
 def init_onload(self):
 if not self.active:
 Session.expunge(self)
 Session.commit()

 But, objects still appear.

 Any idea?

 Thanks, and as always, sorry by my poor English.

 --
 Alex.
 Slothy, the Angry Wombat
 http://angrywombat.comuv.com/portfolio/


 --
 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.


  --
 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.comsqlalchemy%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.




-- 
Alex.
Slothy, the Angry Wombat
http://angrywombat.comuv.com/portfolio/

-- 
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.



[sqlalchemy] Not loading a kind of elements

2011-02-01 Thread slothy Rulez a lot
Hi, list!

I'm trying, to discriminate certain type of rows in the database, in a table
with various attributes, if one attribute, ej: active = Column(Boolean) is
set to False, I don't want it to appear in any kind of query, but still
present in the DB.

My first attempt is define a reconstructor like this:

@orm.reconstructor
def init_onload(self):
if not self.active:
Session.expunge(self)
Session.commit()

But, objects still appear.

Any idea?

Thanks, and as always, sorry by my poor English.

-- 
Alex.
Slothy, the Angry Wombat
http://angrywombat.comuv.com/portfolio/

-- 
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.



[sqlalchemy] Sqlite3 auto

2011-01-28 Thread slothy Rulez a lot
Hi, []

I'm trying to create tables in SQLITE, with a composite PK (id, eid), I want
the id have the auto increment.
I've read this,
http://www.sqlalchemy.org/docs/dialects/sqlite.html#auto-incrementing-behavior,
and following your instructions, added __table_args__ =
{'sqlite_autoincrement':True}
(I'm using declarative), but i'm not having any difference.

This is the debug exit and the declarative code:

2011-01-28 13:48:56,999 INFO sqlalchemy.engine.base.Engine.0x...b9ec
CREATE TABLE elementos_filiales (
id INTEGER,
tipo TEXT,
 timestamp TEXT,
eid VARCHAR(127) NOT NULL,
nombre TEXT,
 eliminado INTEGER,
padre INTEGER,
PRIMARY KEY (id, eid),
 FOREIGN KEY(padre) REFERENCES elementos_multinacionales (id)
)



id = Column(Integer,primary_key=True,nullable=True)
eid = Column(String(132),primary_key=True)



What i'm doing wrong?

Thank you.



-- 
Alex.
Slothy, the Angry Wombat
http://angrywombat.comuv.com/portfolio/

-- 
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.



[sqlalchemy] dynamic modification of foreign keys sqlalchemy

2010-12-01 Thread slothy
Hi!

I'm creating a structure of elements dynamically with declarative,
and I'm not sure if I can modify the mapper to get the new elements
related with a FK. Sorry about my english, is very poor.

This is my function class factory:

def nuevaEtiqueta(self, nombre_etiqueta):
etiqueta = nombre_etiqueta.lower().strip()
nombre_etiqueta = etiquetas_ + etiqueta
dicc = {'__tablename__':nombre_etiqueta,'__table_args__ ':
{'autoload':True}}

id = Column(Integer,primary_key=True);dicc.update({'id':id})
tipo = Column(Text);dicc.update({'tipo':tipo})
contenido_texto =
Column(Text);dicc.update({'contenido_texto':contenido_texto})
contenido_binario =
Column(LargeBinary);dicc.update({'contenido_binario':contenido_binario})
fichero = Column(Text);dicc.update({'fichero':fichero})
ref_elemento = Column(Integer,ForeignKey('elementos_'+etiqueta
+'.id'));dicc.update({'ref_elemento':ref_elemento})

def __init__(self, diccio):
  self.tipo = diccio[tipo]
  if self.tipo == BIN:
self.contenido_binario = diccio[contenido_binario]
self.fichero = diccio[fichero]
  else:
self.contenido_texto = diccio[contenido_texto]
dicc.update({'__init__':__init__})

def __repr__(self):
  aux = ETIQUETA 
  if self.tipo == 'BIN':
return aux +  BINARIA
  else:
return aux + %s - CONTENIDO: %s %
(self.tipo,self.contenido_texto)
dicc.update({'__repr__':__repr__})

clase_etiqueta = type(str(nombre_etiqueta),(Base,),dicc)
self.etiquetas_map.update({nombre_etiqueta:clase_etiqueta})

Now, when a new class is created, I want the mapper adds the FK

I'm trying to do this with session mappers but with no success.

Can you help?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.