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