db.define_table('author',
Field('name', 'string'),
Field('bio', 'text'))
db.define_table('link',
Field('name', 'string'),
Field('description', 'text'))
# a table to store posted Quotes
db.define_table('post',
Field('body','text',label="Post Body"),
Field('posted_on','datetime',readable=False,writable=False),
Field('posted_by','reference auth_user',readable=False,writable=False),
Field('authorID', db.author),
Field('linkID', db.link))
form = SQLFORM.factory(Field('body'),Field('author'),Field('link'))
if form.process().accepted:
link = db.link(name==form.vars.link) or
db.link.insert(name=form.vars.link)
author = db.author(name==form.vars.author) or
db.author.insert(name=form.vars.author)
db.post.insert(body=form.vars.body,authorID=author.id, linkID=link.id)
On Monday, 4 November 2013 14:37:34 UTC-6, Noah wrote:
>
> I have 3 tables defined in my model like so:
>
> db.define_table('author',
> Field('name', 'string'),
> Field('bio', 'text'))
>
>
> db.define_table('source',
> Field('name', 'string'),
> Field('description', 'text'))
>
>
> # a table to store posted Quotes
> db.define_table('post',
> Field('body','text',label="Post Body"),
> Field('posted_on','datetime',readable=False,writable=False),
> Field('posted_by','reference auth_user',readable=False,writable=False
> ),
> Field('authorID', db.author),
> Field('linkID', db.link))
>
>
> I want to create a form that will allow the users to submit a post using
> the following inputs:
>
> - Post Body (db.post.body)
> - Author Name (db.author.name)
> - Link Name (db.link.name)
>
> If the author already exists in the database, no record should be created.
> If the link already exists then no record should be created either.
>
> A record should be added to post containing either the newly created or
> existing IDs for Author and Link.
>
> How would I go about doing this? I am extremely new to Web2Py.
> Thanks for your help!
>
--
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/groups/opt_out.