SQLFORM.Smartgrid and with parent table in Linked Tables

318 views
Skip to first unread message

Michael Hall

unread,
Apr 29, 2013, 8:32:10 AM4/29/13
to web...@googlegroups.com
I would like to have a smartgrid that references its parent table in linked_tables, what is the web2py way of doing this? I have found some help in this thread: https://groups.google.com/forum/?fromgroups=#!topic/web2py/vDGJdct550Q but the solution is a bit sketchy due to it modifying sqlhtml.py.

Lets take this model:

db.define_table(
   
'contact',
   
Field('name'),
   
Field('address'),
   
format = '%(name)s')

db.define_table(
   
'courses',
   
Field('student_id',db.person),
   
Field('course_name'),
   
Field('pass_mark', 'text'),
    format = '%(name)s')


I want a smartgrid for courses that shows all the courses records and has the contact table in linked tables. That way I have an easy way to view all course data and easily check out the contact data of the person doing the course. This smartgrid is used by people who mark courses and require quick access to the data in the courses table without having to go via the "contact" table.

In a perfect world I would create this smartgrid like so:
def courseview():
    form = SQLFORM.smartgrid(db.courses,linked_tables=['contact'])
    return locals()

However this does not work because the contact table is the parent.

What is the best way of achieving my required result?

Massimo Di Pierro

unread,
Apr 29, 2013, 10:50:30 AM4/29/13
to web...@googlegroups.com
I do not see any relation between courses and contact.

Michael Hall

unread,
Apr 29, 2013, 11:31:17 AM4/29/13
to web...@googlegroups.com

My bad, the model in my example should be:

db.define_table(
   
'contact',
   
Field('name'),
   
Field('address'),
   
format = '%(name)s')

db.define_table(
   
'courses',
   
Field('student_id',db.person),
   
Field('course_name'),
   
Field('pass_mark', 'text'),
    format = '%(name)s')

Michael Hall

unread,
Apr 29, 2013, 11:38:09 AM4/29/13
to web...@googlegroups.com
Doh did it again, its been a long day, the model with the correct reference is
db.define_table(
   
'contact',
   
Field('name'),
   
Field('address'),
   
format = '%(name)s')

db.define_table(
   
'courses'
,
   
Field('student_id',db.contact),
   
Field('course_name'),
   
Field('pass_mark', 'text'),
    format = '%(name)s')


On Monday, 29 April 2013 13:32:10 UTC+1, Michael Hall wrote:

Anthony

unread,
Apr 29, 2013, 11:39:23 AM4/29/13
to web...@googlegroups.com
Isn't that the same model?

Mike Pixael

unread,
Apr 29, 2013, 11:46:04 AM4/29/13
to web...@googlegroups.com
Yeah, been a long day it should be:
db.define_table(
   
'contact',
   
Field('name'),
   
Field('address'),
   
format = '%(name)s')

db.define_table(
   
'courses'
,
   
Field('student_id',db.contact),
   
Field('course_name'),
   
Field('pass_mark', 'text'),
    format = '%(name)s') The reference in the table courses should be db.contact.


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/yWXaGpbH28M/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

joaquim carvalho

unread,
Nov 16, 2015, 7:46:54 PM11/16/15
to web2py-users
Hi Massimo

I use Web2py for some web development I've been working. Thanks to you web2py is a great tool.

I am writing to give you a sugestion, if I might: why not create a "linked_tables_placement" in the SQLFORM.smartgrid? It will be very usefull. I think it is simple to implement.

Sorry for my english
Reply all
Reply to author
Forward
0 new messages