Do not do this:

db.define_table('image',
                Field('user_id', 'reference auth_user'),
                Field('file', 'upload'),
                Field('description', 'text'))

do

db.define_table('image',
                Field('file', 'upload'),
                Field('description', 'text'),
                auth.signature)

and the db.image.created_by will be a reference to the user who uploaded 
the image.

On Friday, 31 July 2015 12:11:35 UTC-5, Pablo Andrés Ortega Chávez wrote:
>
> Hello Guys,
>
>
> Just starting with Web2Py.
>
>
> I'm working on a project and need to do the following:
>
>
> I have image defined in the DB like this:
>
> db.define_table('image',
>                 Field('user_id', 'reference auth_user'),
>                 Field('file', 'upload'),
>                 Field('description', 'text'))
>
> And then:
>
> db.image.user_id.requires = IS_IN_DB(db, db.auth_user.id, 
> '%(displayed_name)s')
>
>
> Then I created a function, so only registered users may upload or send 
> pictures:
>
> @auth.requires_login()
> def upload():
>     form = SQLFORM(db.image)
>     if form.process().accepted:
>         response.flash = 'Your Photo has been sent!'
>     return dict(form=form)
>
>
>
> The problem I've been having is I need to bind every uploaded picture by a 
> user to that specific user. I don't even need the form to show a list of 
> users to select which one is the owner of the photo, because the owner must 
> always be the logged in user.
>
> However, I haven't managed to find a way of doing that. Read the 
> documentation but couldn't find an example.
>
> Right now, with the code I have, the form would show me the list of all 
> registered users to select one to bind the photo with.
>
>
> I really appreciate your help.
>
>
> Thanks!
>

-- 
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