[web2py] Re: Bug in database administration
This is not a bug but a limitation in syntax: You cannot do: db.define_table('cgc_schedule', ... format='%(training.short_title)s (%(training_date)s)') because only fields of the table itself can be used in the representation of a record. In order to retrieve training.short_title for a record of table cgc_schedule, web2py would have to go a recursive select and we do not want to do that silently because can be expensive. There is another notation: db.define_table('cgc_schedule', ... format=lambda row: '%s %s' % (row.training.short_title, row.training_date)) and this will do what you ask since it is more explicit. On Thursday, 7 February 2013 09:31:56 UTC-6, Calycé wrote: Hi all, I have an error in the database administration when using the following code in db.py: db.define_table('cgc_service_categories', Field('category', 'string', required=True), Field('description', 'text', required=True), Field('image', 'upload', required=True), Field('display_order', 'integer'), Field('link', 'string'), format='%(category)s') db.define_table('cgc_trainings', Field('category', db.cgc_service_categories), Field('disporder', 'integer'), Field('title', 'string', required=True), Field('short_title', 'string', required=True), Field('duration', 'string', required=True), Field('planning', 'text', required=True), Field('typical', 'text'), Field('price', 'integer'), Field('training_checks', 'boolean'), Field('image', 'upload'), format='%(short_title)s') db.define_table('cgc_schedule', Field('training', db.cgc_trainings), Field('location', 'string'), Field('training_date', 'date'), Field('vacancies', 'integer'), format='%(training.short_title)s (%(training_date)s)') db.define_table('cgc_booking', Field('training_date', db.cgc_schedule), Field('company', 'string'), Field('first_name', 'string'), Field('last_name', 'string'), Field('phone', 'string'), Field('email', 'string'), Field('seats', 'integer')) It works when I browse the existing records, but if I try to edit a record or insert a new one with the database administration in the cgc_booking table, I receive the following error: type 'exceptions.AttributeError' 'Table' object has no attribute 'training.short_title' If I change the format for the cgc_schedule table to %(training)s (%(training_date)s) it works but having only the id is useless in this case. Is it a bug in the database administration or am I doing something wrong ? BTW, I'm using 2.3.2. Thanks for your help. Calycé -- --- 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: Bug in database administration
I found a solution/workaround. For the records, I changed the format for the table cgc_schedule. Old one: format='%(training.short_title)s (%(training_date)s)' New one: format=lambda row: row.training.short_title + ' (' + row.training_date. strftime('%d-%m-%Y') + ')' With that new format, it works. I'm still wondering why I need to use a lambda to have it working. If someone has a clue I'm all ears ;-) On Thursday, February 7, 2013 4:31:56 PM UTC+1, Calycé wrote: Hi all, I have an error in the database administration when using the following code in db.py: db.define_table('cgc_service_categories', Field('category', 'string', required=True), Field('description', 'text', required=True), Field('image', 'upload', required=True), Field('display_order', 'integer'), Field('link', 'string'), format='%(category)s') db.define_table('cgc_trainings', Field('category', db.cgc_service_categories), Field('disporder', 'integer'), Field('title', 'string', required=True), Field('short_title', 'string', required=True), Field('duration', 'string', required=True), Field('planning', 'text', required=True), Field('typical', 'text'), Field('price', 'integer'), Field('training_checks', 'boolean'), Field('image', 'upload'), format='%(short_title)s') db.define_table('cgc_schedule', Field('training', db.cgc_trainings), Field('location', 'string'), Field('training_date', 'date'), Field('vacancies', 'integer'), format='%(training.short_title)s (%(training_date)s)') db.define_table('cgc_booking', Field('training_date', db.cgc_schedule), Field('company', 'string'), Field('first_name', 'string'), Field('last_name', 'string'), Field('phone', 'string'), Field('email', 'string'), Field('seats', 'integer')) It works when I browse the existing records, but if I try to edit a record or insert a new one with the database administration in the cgc_booking table, I receive the following error: type 'exceptions.AttributeError' 'Table' object has no attribute 'training.short_title' If I change the format for the cgc_schedule table to %(training)s (%(training_date)s) it works but having only the id is useless in this case. Is it a bug in the database administration or am I doing something wrong ? BTW, I'm using 2.3.2. Thanks for your help. Calycé -- --- 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: Bug in database administration
oops, looks like you were faster than me ;-) Anyway thanks for your help. On Thursday, February 7, 2013 5:39:24 PM UTC+1, Massimo Di Pierro wrote: This is not a bug but a limitation in syntax: You cannot do: db.define_table('cgc_schedule', ... format='%(training.short_title)s (%(training_date)s)') because only fields of the table itself can be used in the representation of a record. In order to retrieve training.short_title for a record of table cgc_schedule, web2py would have to go a recursive select and we do not want to do that silently because can be expensive. There is another notation: db.define_table('cgc_schedule', ... format=lambda row: '%s %s' % (row.training.short_title, row.training_date)) and this will do what you ask since it is more explicit. On Thursday, 7 February 2013 09:31:56 UTC-6, Calycé wrote: Hi all, I have an error in the database administration when using the following code in db.py: db.define_table('cgc_service_categories', Field('category', 'string', required=True), Field('description', 'text', required=True), Field('image', 'upload', required=True), Field('display_order', 'integer'), Field('link', 'string'), format='%(category)s') db.define_table('cgc_trainings', Field('category', db.cgc_service_categories), Field('disporder', 'integer'), Field('title', 'string', required=True), Field('short_title', 'string', required=True), Field('duration', 'string', required=True), Field('planning', 'text', required=True), Field('typical', 'text'), Field('price', 'integer'), Field('training_checks', 'boolean'), Field('image', 'upload'), format='%(short_title)s') db.define_table('cgc_schedule', Field('training', db.cgc_trainings), Field('location', 'string'), Field('training_date', 'date'), Field('vacancies', 'integer'), format='%(training.short_title)s (%(training_date)s)') db.define_table('cgc_booking', Field('training_date', db.cgc_schedule), Field('company', 'string'), Field('first_name', 'string'), Field('last_name', 'string'), Field('phone', 'string'), Field('email', 'string'), Field('seats', 'integer')) It works when I browse the existing records, but if I try to edit a record or insert a new one with the database administration in the cgc_booking table, I receive the following error: type 'exceptions.AttributeError' 'Table' object has no attribute 'training.short_title' If I change the format for the cgc_schedule table to %(training)s (%(training_date)s) it works but having only the id is useless in this case. Is it a bug in the database administration or am I doing something wrong ? BTW, I'm using 2.3.2. Thanks for your help. Calycé -- --- 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.