Thank You Massimo!

Yesterday after I posted my question, I found another post here and went 
ahead and do this:

On the image table I defined:

*Field('user_id', db.auth_user, default=auth.user_id, writable=False, 
readable=False),*

And then I also defined this:

*db.image.user_id.requires = IS_IN_DB(db, db.auth_user.id, 
'%(displayed_name)s')*

That worked like a charm.

I understand there are some differences between the approach I implemented 
yesterday and the one you're suggesting. I see that there are additional 
fields in the image table created, with the information from the user.

What would be the main disadvantages of using the first method, instead of 
the "*auth.signature*" method?

And, the field* image.is_active* was also created, and the value for the 
picture I uploaded is *True*. Is that possible to be changed by default to 
*False*, for example? What is the use for that field?

Thank you very much for your support!

PD: I found last night your Vimeo account with the tutorials. Very nice. I 
watched one and learned how to use the Bootstrap 3 features, I'm playing 
with that and the application I'm building is growing fast! I think that, 
so far, Web2Py is a really powerful framework and helps you build 
applications fast. I'm gonna be around here asking questions a lot, hahaha.

Thanks again.


El viernes, 31 de julio de 2015, 12:24:29 (UTC-5), Massimo Di Pierro 
escribió:
>
> 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