Reputation: 111
I'm just starting out on the web2py and really can't get pass the SQLFORM.grid part. My data is in mySQL db and i'm trying to call a query for it.
I defined the table but without the id field because i called it "itemNumber" and used that as my id field.
db.define_table('items',
Field('itemNumber', 'integer'),
Field('title', 'string'),
Field('price', 'integer'),
Field('numSold', 'integer'))
in my default.py
def display_form():
db.items.id.readable = False
query = (db.items.numSold)
fields = (db.items.price, db.items.numSold, db.items.title)
headers = {'items.price': 'Price', 'items.numSold': '# Sold', 'items.title': 'Title'}
default_sort_order = [db.items.numSold]
form = SQLFORM.grid(query=query, fields=fields, headers=headers, orderby=default_sort_order, create=False, deletable=False, editable=False, maxtextlength=64,
paginate = 25)
return dict(form=form)
The error provided on the html page: Query Not Supported: (1054, u"Unknown column 'items.id' in 'field list'") No records found
I thought i read that SQLFORM.grid automatically calls for ".id" But what if the unique key, in my case, is named itemNumber instead of id?
How do i turn that off?
Thanks so much,
John
Upvotes: 0
Views: 3203
Reputation: 25536
Your table definition should start as follows:
db.define_table('items',
Field('itemNumber', 'id'),
When you specify the field type as "id", web2py will treat that field as the auto-incrementing integer primary key and will not create a separate field named "id".
Upvotes: 2