This is one of the solutions I was considering as I tried to formulate my 
question. I hadn't found that particular section, but I remembered reading 
something about dealing with multiple tables.

One issue that doesn't solve is an ajax call to add to a separate table. In 
the case of CKEditor, if I insert an image to my text, it uploads the image 
via ajax, so if I keep with the tablename/record_id, then I need to send 
the record_id of the article that CKEditor is working on. Without a 
pre-existing article, I cannot insert the image through CKEditor when 
creating a new article. I would have to save the article then edit it to 
start inserting images.

For my current project, I am taking out the option of adding images that 
way, so the SQLFORM.factory() option may be the way to go. I will need to 
change how my attachments are uploaded, since they currently submit via 
ajax too.

Thanks.

On Thursday, July 24, 2014 4:07:11 PM UTC-7, Anthony wrote:
>
> Have you looked at 
> http://web2py.com/books/default/chapter/29/07/forms-and-validators#One-form-for-multiple-tables
> ?
>
> Anthony
>
> On Thursday, July 24, 2014 6:31:11 PM UTC-4, Carlos Hanson wrote:
>>
>> Greetings,
>>
>> Using plugin_attachments as an example, it defines a table like the 
>> following:
>>
>> db.define_table('plugin_attachments_attachment', 
>>     Field('tablename', readable=False, writable=False), 
>>     Field('record_id', 'integer', readable=False, writable=False),
>>     [...])
>>
>> That suggests that I need to create the record to which I want to add an 
>> attachment before I add the attachment. Since I want to create the record 
>> and add the attachment in one view, I do the following:
>>
>> def add():
>>     article_id = db.article.insert()
>>     redirect(URL('edit', args=[article_id]))
>>
>> def edit():
>>     article_id = request.args[0]
>>     form = crud.update(db.article, article_id, next='view/[id]')
>>     attachments = PluginAttachments(db.article, article_id)
>>     return locals()
>>
>> Ideally, I would like one function for add and one for edit because the 
>> current method complicates the code in a new project. Maybe I need to 
>> figure out how to submit multiple forms at once, then insert the extras, 
>> like attachments, after checking form.accepted.
>>
>> Part of the problem is that I am using CKEditor and it wants to upload 
>> images to the server before I ever hit Save on the article.
>>
>> Is there a suggested way to create a record and provide an update form in 
>> one controller? Should I just create one big custom form (SQLFORM.factory), 
>> then manage the inserts myself?
>>
>> Thanks in advance for your suggestions and experience. Let me know if you 
>> need more clarification.
>>
>> Carlos Hanson
>>
>>
>>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to