SQLFORM.factory without a database table

238 views
Skip to first unread message

A36_Marty

unread,
Feb 14, 2014, 12:03:33 AM2/14/14
to web...@googlegroups.com
I would like to make a grid-like screen without an underlying database table.

I've read the section in the book:

I get everything except how to create and send records to the SQLFORM.factory.  The document mentions a table named "no_table", but how do I create this table without storing it in the database?  

Could someone provide a simple example?

Also, will the SQLFORM.factory produce a grid/table or just single-record create/edit forms?

Sorry for the elementary question, but I don't quite grasp this no-database concept.

Thanks in advance.


Anthony

unread,
Feb 14, 2014, 9:36:17 AM2/14/14
to web...@googlegroups.com
SQLFORM.factory is for generating forms, not grids.

The grid requires an actual database, though you can use a SQLite memory database: https://groups.google.com/d/msg/web2py/g4Mon6PvNFc/jytHfEnOXTIJ.

Anthony

Richard Vézina

unread,
Feb 14, 2014, 10:06:27 AM2/14/14
to web2py-users
To insert/update record with .factory() you can do something like that :

if form.process().accepted:
    if condition when update mode is not meat:
        id = db.underlying_table.insert(field1=form.vars.field1, ...)  # You keep the id in cas you need it to insert some information in another table.
    elif condition when update form mode:
        db(db.underlying_table.record_id == request.vars.record_id).update(field1=form.vars.field1)


And you can consider a dict comprehension so you don't actually have to write too much :

id = db.lotns_sample.insert(**{str(var): form.vars[var] for var in form.vars})  # You can filter form.vars to make sure you insert only the proper fields into the proper table in case you have fields from differents tables in you .factory() form.

:)

You can also use the web2py function to filter the field :

id = db.underlying_table.insert(**db.underlying_table._filter_fields(form.vars))

Richard


--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Dave S

unread,
Feb 18, 2014, 3:53:38 PM2/18/14
to web...@googlegroups.com


On Thursday, February 13, 2014 9:03:33 PM UTC-8, A36_Marty wrote:
I would like to make a grid-like screen without an underlying database table.


is this something interactive, where the user is entering data?  Or is it just a display?  If the latter, perhaps you just want the TABLE helper.

/dps

Richard Vézina

unread,
Feb 18, 2014, 4:14:18 PM2/18/14
to web2py-users
Don't understand your question... It generate a self validating form base on field validator defined in models if you clone you field from there or the Field() if you create field input on the fly...

Do you want a form? or a Grid?

If the latter there the TABLE() helper...

Richard




--

Marty McCasland

unread,
Feb 18, 2014, 4:21:03 PM2/18/14
to web...@googlegroups.com, web2py-users
Was aiming to create a grid. Just used an in-memory SQLite db to achieve the grid.   Works great. 

Sent from my iPad
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/ZTvWwT9uuNg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages