uploading a file to a new table referencing session from previous table

20 views
Skip to first unread message

aetag...@gmail.com

unread,
Apr 1, 2016, 10:37:07 AM4/1/16
to web2py-users
I am not sure if I worded my question correctly, sorry for confusion.

Consider:

db.define_table('form1',
    Field('number', 'integer'),
    Field('field1', 'string'),
    Field('field2', 'string),
    Field('field3', 'integer'))

db.define_table('formfile',
    Field('number_id', db.form1),
    Field('form1_file', 'upload'))


field1, field2, field3 is generated dynamically for form1, but there is always only one form field for the number field.

Given this example:

User enters 2.
This generates the form:

number
field1_0
field2_0
field3_0
field1_1
field2_1
field3_1


I take the values entered form this session, do something to them, then I want to insert them into a file.

I am doing this in a different controller, and I would like to know if I am going about this in the right way because having two tables is throwing me off.

I want to upload this file from this session to the table formfile, which will reference form1, but I want the table to display the number field and the file that is associated with that number field id from that session for each specific user.

So each time form1 is filled, there will be a file correlating to that session in the formfile table.
Does this make sense with how I have my tables defined?

Message has been deleted

aetag...@gmail.com

unread,
Apr 1, 2016, 12:58:36 PM4/1/16
to web...@googlegroups.com
This is working, I am able to upload a file containing information from the session, but when I try displaying SQLFORM.grid in the next view, it says no records found..but the upload was successful because the file is in my uploads folder. So I think I am doing something wrong with my referencing in the second table. I want to the file to upload according to the value from the session of field "number"


I do the upload like this:

controller:

def upFile():
    vars = request.vars
    arrvars = [] //i sort the form.vars and fill them in this array
    //i open a file and insert values from array into it
    db.formfile.form1_file.store(file, 'form1file.xlsx')
    //then i redirect to next controller to display sqlform grid
    return dict(arrvars=arrvars)

def form1files():
    grid = SQLFORM.grid(db.formfile)
    return locals()


Any idea as to why this would be occurring? Thank you

Reply all
Reply to author
Forward
0 new messages