[sqlalchemy] Re: filtered or computed version of an existing relation?

2009-06-21 Thread allen.fowler
Thank you, Michael. On Jun 18, 9:41 am, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 18, 2009, at 2:27 AM, AF wrote: OK, next question. Well... two related questions.  :) 1)  In general, inside an object's method def, where I am doing arbitrary calculations, how can I get

[sqlalchemy] Random value for field by default?

2009-06-21 Thread AF
Hello, Perhaps this is more of a Python question that SQLalchemy.. but... How can I assign a random number to a DB field by default? I tried: default = random.randrange(1000,1) on the table definition, but I get the same number each time? Ideas?

[sqlalchemy] Re: Random value for field by default?

2009-06-21 Thread Bobby Impollonia
default = lambda: random.randrange(1000,1) On Sun, Jun 21, 2009 at 1:32 PM, AF allen.fow...@yahoo.com wrote: Hello, Perhaps this is more of a Python question that SQLalchemy.. but... How can I assign a random number to a DB field by default? I tried: default =

[sqlalchemy] Re: Random value for field by default?

2009-06-21 Thread allen.fowler
OK, never mind... I solved it. The default = random.randrange(1000,1) code was happily taking the static return value. Duh. I changed it to: default = lambda: random.Random().randrange(2000,8000) I dunno if the extra Random() is needed, but it can't hurt, right? On Jun 21, 4:32 pm,

[sqlalchemy] Re: Random value for field by default?

2009-06-21 Thread allen.fowler
default = lambda: random.randrange(1000,1) Seems we crossed in the interwebs.. :) Is it safe to do this, or do you need to do default = lambda: random.Random()randrange(1000,1) ? I ask since I have several tables that this needs to be applied to. Thank you

[sqlalchemy] Re: Random value for field by default?

2009-06-21 Thread Bobby Impollonia
Yes, it is safe. Python's underlying random number generation is threadsafe. There is no need to create a new RNG each time to generate a single number. On Sun, Jun 21, 2009 at 1:53 PM, allen.fowlerallen.fow...@yahoo.com wrote: default = lambda: random.randrange(1000,1) Seems we

[sqlalchemy] Validators: Define at table / mapper level ?

2009-06-21 Thread AF
Hello, Can validators be defined at table / mapper level? (Is it even a good idea?) I ask, since it's at the table definition layer that I define what datatypes my columns have, so it seems natural to place the policing function there as well. :)