Thank you Anthony!
That was exactly what I did last night, with a post I found here.
I just replied here with some questions, so I'll have to wait for my post
to be approved and published so you can see it.
I'd appreciate any insights.
Regards,
Pablo.
El viernes, 31 de julio de 2015, 12:53:52 (UTC-5), Anthony escribió:
>
> Using auth.signature is a good approach (though may be overkill if you
> don't need the other fields it creates). But for reference, to achieve what
> you want, just hide the user_id field and give it a default value:
>
> Field('user_id', 'reference auth_user', writable=False, default=auth.
> user_id)
>
> Anthony
>
> On Friday, July 31, 2015 at 1:24:29 PM UTC-4, Massimo Di Pierro wrote:
>>
>> 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.