[web2py] Re: using legacy mysql tables

2013-10-13 Thread James Thompson
Thanks!
It works now.

On Saturday, October 12, 2013 2:13:48 AM UTC-10, Niphlod wrote:

 did you add a format= attribute for the referenced table ?



 On Saturday, October 12, 2013 4:28:15 AM UTC+2, James Thompson wrote:

 I tried it without the dotted notation, it gets rid of the error message, 
 but
 in the admin interface it shows raw integer values for the foreign key 
 fields rather than the value from the referenced table.
 Do I need to add something else?


 On Friday, October 11, 2013 2:02:42 AM UTC-10, Niphlod wrote:

 I don't think that you need to use the dotted notation for the 
 reference. you just have a table whose pk is model_id instead of id.
 Try just 'reference car_model'.

 PS: keyed table in web2py are when you need to pass a primarykey=[] to 
 the table definition in your case it's just a matter of column names 
 more than one of table structure.

 On Friday, October 11, 2013 12:25:33 PM UTC+2, James Thompson wrote:

 Wondering about support for legacy Mysql tables in web2py.  Read the 
 book section on legacy databases, but keep getting:
 type 'exceptions.SyntaxError' keyed tables can only reference other 
 keyed tables (for now)
 My mysql db and web2py models like something like this:

 CREATE TABLE `car_models` ( 
   `model_id` int(10) unsigned NOT NULL auto_increment, 
   `model_name` text NOT NULL, 
   PRIMARY KEY  (`model_id`) 
 ) 

 CREATE TABLE `cars` ( 
   `car_id` int(10) unsigned NOT NULL auto_increment, 
   `model_id` int(10) unsigned NOT NULL, 
   PRIMARY KEY  (`car_id`) 
 ) 

 web2py model:

 x_db = DAL('mysql://user:password@db/database')

 x_db.define_table('car_models', 
 Field('model_id','id'), 
 Field('model_name','string'), 
 migrate=False 
 ) 

 x_db.define_table('cars', 
 Field('car_id','id'), 
 Field('model_id','reference car_models.model_id'), 
 Field('note','text'), 
 migrate=False 
 ) 




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] using legacy mysql tables

2013-10-11 Thread James Thompson
Wondering about support for legacy Mysql tables in web2py.  Read the book 
section on legacy databases, but keep getting:
type 'exceptions.SyntaxError' keyed tables can only reference other keyed 
tables (for now)
My mysql db and web2py models like something like this:

CREATE TABLE `car_models` ( 
  `model_id` int(10) unsigned NOT NULL auto_increment, 
  `model_name` text NOT NULL, 
  PRIMARY KEY  (`model_id`) 
) 

CREATE TABLE `cars` ( 
  `car_id` int(10) unsigned NOT NULL auto_increment, 
  `model_id` int(10) unsigned NOT NULL, 
  PRIMARY KEY  (`car_id`) 
) 

web2py model:

x_db = DAL('mysql://user:password@db/database')

x_db.define_table('car_models', 
Field('model_id','id'), 
Field('model_name','string'), 
migrate=False 
) 

x_db.define_table('cars', 
Field('car_id','id'), 
Field('model_id','reference car_models.model_id'), 
Field('note','text'), 
migrate=False 
) 


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: using legacy mysql tables

2013-10-11 Thread James Thompson
I tried it without the dotted notation, it gets rid of the error message, 
but
in the admin interface it shows raw integer values for the foreign key 
fields rather than the value from the referenced table.
Do I need to add something else?


On Friday, October 11, 2013 2:02:42 AM UTC-10, Niphlod wrote:

 I don't think that you need to use the dotted notation for the reference. 
 you just have a table whose pk is model_id instead of id.
 Try just 'reference car_model'.

 PS: keyed table in web2py are when you need to pass a primarykey=[] to the 
 table definition in your case it's just a matter of column names more 
 than one of table structure.

 On Friday, October 11, 2013 12:25:33 PM UTC+2, James Thompson wrote:

 Wondering about support for legacy Mysql tables in web2py.  Read the book 
 section on legacy databases, but keep getting:
 type 'exceptions.SyntaxError' keyed tables can only reference other 
 keyed tables (for now)
 My mysql db and web2py models like something like this:

 CREATE TABLE `car_models` ( 
   `model_id` int(10) unsigned NOT NULL auto_increment, 
   `model_name` text NOT NULL, 
   PRIMARY KEY  (`model_id`) 
 ) 

 CREATE TABLE `cars` ( 
   `car_id` int(10) unsigned NOT NULL auto_increment, 
   `model_id` int(10) unsigned NOT NULL, 
   PRIMARY KEY  (`car_id`) 
 ) 

 web2py model:

 x_db = DAL('mysql://user:password@db/database')

 x_db.define_table('car_models', 
 Field('model_id','id'), 
 Field('model_name','string'), 
 migrate=False 
 ) 

 x_db.define_table('cars', 
 Field('car_id','id'), 
 Field('model_id','reference car_models.model_id'), 
 Field('note','text'), 
 migrate=False 
 ) 




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: SQLTABLE and foreign key fields

2013-10-10 Thread James Thompson
I'm a little confused by:
db.dog.owner.represent = None
SQLFORM.grid(db.dog.represent==db.person.id)

Why would we use db.dog.represent==db.person.id
rather than db.dog.owner==db.person.id
here?

Thanks.




On Wednesday, October 9, 2013 3:20:08 PM UTC-10, Massimo Di Pierro wrote:

 It depends. It may. 

 For example given:

 db.define_table('person',Field('name'),format='%(name)s')
 db.define_table('dog',Field('name'),Field('owner','reference dog'))

 if you do:

 SQLFORM.grid(db.dog.owner==db.person.id)

 it will do a recursive select for each row to find a representation of 
 db.dog.owner.

 You can disabled this:

 db.dog.owner.represent = None
 SQLFORM.grid(db.dog.represent==db.person.id)

 or hide it

 db.dog.owner.readable = False
 SQLFORM.grid(db.dog.represent==db.person.id)

 or cache it:

 db.dog.owner.represent = lambda v,r: cache.ram('person-%s'%v, lambda v=v: 
 v and '%(name)s'%db.person(v), None)
 SQLFORM.grid(db.dog.represent==db.person.id)

 You can always add the {{=response.toolbar()}} to see all the database 
 queries.


 On Wednesday, 9 October 2013 14:39:07 UTC-5, James Thompson wrote:

 When using SQLTABLE (or something like: {{=query_results}}) to display 
 rows in a view, foreign key fields display data from their related table.
 Is web2py doing individual queries for each of these fields?




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Tracking the date/time of a field change.

2013-10-10 Thread James Thompson
I looked at record versioning, but, if I use something like: 
db.mytable._before_update
then when the _before_update function is called, no changes have been made 
to the database yet.
So to get the old value of the field, it seems like I need to read the 
current database row that is about to be updated, (unless web2py has this 
data cached somewhere already). Then I can compare the old field value to 
the value about to be written to see if it is changing.


On Wednesday, October 9, 2013 3:25:07 PM UTC-10, 黄祥 wrote:

 had you already take a look record versioning?

 taken from book :
 Record versioning
 _enable_record_versioning

 It is possible to ask web2py to save every copy of a record when the 
 record is individually modified.

 so if you combine record versioning, auth signature that have modified 
 date field with before and after callback (to compare the archieve table 
 with the original one), i think you can get what you want.

 best regards,
 stifan


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: SQLTABLE and foreign key fields

2013-10-10 Thread James Thompson
Thanks.
I assume also that:
db.define_table('dog',Field('name'),Field('owner','reference dog'))
should be:
db.define_table('dog',Field('name'),Field('owner','reference person'))
?

On Thursday, October 10, 2013 5:37:16 AM UTC-10, Massimo Di Pierro wrote:

 Oops. A typo. I fixed it in the previous message.

 On Wednesday, 9 October 2013 21:41:46 UTC-5, James Thompson wrote:

 I'm a little confused by:
 db.dog.owner.represent = None
 SQLFORM.grid(db.dog.represent==db.person.id)

 Why would we use db.dog.represent==db.person.id
 rather than db.dog.owner==db.person.id
 here?

 Thanks.




 On Wednesday, October 9, 2013 3:20:08 PM UTC-10, Massimo Di Pierro wrote:

 It depends. It may. 

 For example given:

 db.define_table('person',Field('name'),format='%(name)s')
 db.define_table('dog',Field('name'),Field('owner','reference dog'))

 if you do:

 SQLFORM.grid(db.dog.owner==db.person.id)

 it will do a recursive select for each row to find a representation of 
 db.dog.owner.

 You can disabled this:

 db.dog.owner.represent = None
 SQLFORM.grid(db.dog.represent==db.person.id)

 or hide it

 db.dog.owner.readable = False
 SQLFORM.grid(db.dog.represent==db.person.id)

 or cache it:

 db.dog.owner.represent = lambda v,r: cache.ram('person-%s'%v, lambda 
 v=v: v and '%(name)s'%db.person(v), None)
 SQLFORM.grid(db.dog.represent==db.person.id)

 You can always add the {{=response.toolbar()}} to see all the database 
 queries.


 On Wednesday, 9 October 2013 14:39:07 UTC-5, James Thompson wrote:

 When using SQLTABLE (or something like: {{=query_results}}) to display 
 rows in a view, foreign key fields display data from their related table.
 Is web2py doing individual queries for each of these fields?




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] SQLTABLE and foreign key fields

2013-10-09 Thread James Thompson
When using SQLTABLE (or something like: {{=query_results}}) to display rows 
in a view, foreign key fields display data from their related table.
Is web2py doing individual queries for each of these fields?


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Tracking the date/time of a field change.

2013-10-09 Thread James Thompson
It looks like in a DAL callback, the original values of the record are not 
available?
So I would need to do read the old row from the database to get the old 
values of the row to determine if the value of a field has changed?
Thanks.

On Monday, October 7, 2013 10:35:25 AM UTC-10, Niphlod wrote:

 why don't you use callbacks ? they are the most useful feature in DAL's in 
 my POV.

 http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#before-and-after-callbacks

 On Monday, October 7, 2013 8:55:29 PM UTC+2, James Thompson wrote:

 I thought default=request.now and update=request.net reflect changes in 
 the record as a whole?
 I'm looking for something that only updates when the value of the status 
 field changes. 

 On Monday, October 7, 2013 3:31:33 AM UTC-10, 黄祥 wrote:

 i think you can achieve it with default.
 e.g. 
 Field('f_status_change_dt', type='datetime',
   label=T('Status Change Dt')*, default=request.now*)

 or if you set auth.signature or record_versioning, web2py automatically 
 do that for you.

 ref:

 http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Record-versioning

 http://web2py.com/books/default/chapter/29/09/access-control#Record-versioning

 best regards,
 stifan



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Tracking the date/time of a field change.

2013-10-07 Thread James Thompson
I need to track the date/time of the last change to one field in a row.
Example:

Field('f_status', type='text',
  label=T('Status'), requires=IS_IN_SET(['status1', 'status2', 
'status3'])),
Field('f_status_change_dt', type='datetime',
  label=T('Status Change Dt')),

where 'status_change_dt' would be automatically be set to the current 
date/time whenever the value of the 'status' field changed.
   
I could do this in my own app code, but I was hoping for something in the 
model so that it happens in the web2py admin, or any other apps that use 
this model as well.

Thanks.



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Tracking the date/time of a field change.

2013-10-07 Thread James Thompson
I thought default=request.now and update=request.net reflect changes in the 
record as a whole?
I'm looking for something that only updates when the value of the status 
field changes. 

On Monday, October 7, 2013 3:31:33 AM UTC-10, 黄祥 wrote:

 i think you can achieve it with default.
 e.g. 
 Field('f_status_change_dt', type='datetime',
   label=T('Status Change Dt')*, default=request.now*)

 or if you set auth.signature or record_versioning, web2py automatically do 
 that for you.

 ref:

 http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Record-versioning

 http://web2py.com/books/default/chapter/29/09/access-control#Record-versioning

 best regards,
 stifan


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.