Woww.. like a charm! hehe... Thanks Anthony!
I am finding it a bit difficult to catch and understand some things. New to
programming in objects and frameworks.
Thanks again for the hand
El miércoles, 26 de febrero de 2014 19:46:36 UTC-3, Anthony escribió:
>
> db.uploads.up_post.requires = IS_IN_DB(db(db.post.author == auth.user_id),
> db.post,'%(summary)s')
>
> The IS_IN_DB validator takes a Set object as the first argument, which can
> be used to filter the allowable records.
>
> Anthony
>
> On Wednesday, February 26, 2014 5:23:41 PM UTC-5, brahama von wrote:
>>
>> Hi guys!
>>
>> How is the approach to do this?
>>
>> Here's the model
>> -------------------------
>> db.define_table('uploads',
>> Field('up_name','string',requires=IS_NOT_EMPTY()),
>> Field('mainfile','upload'),
>> Field('thumb','upload',writable=False,readable=False),
>> Field('up_author',db.auth_user,requires=IS_NOT_EMPTY()),
>> Field('up_post','reference post'),
>> format='%(up_name)s')
>>
>> db.uploads.up_author.writable = db.uploads.up_author.readable = False
>>
>> db.define_table('post',
>> Field('summary','string',requires=IS_NOT_EMPTY()),
>> Field('author',db.auth_user,requires=IS_NOT_EMPTY()),
>> Field('body','text'),
>> format='%(summary)s')
>>
>> db.post.author.writable = db.post.author.readable = False
>> db.uploads.up_post.requires = IS_IN_DB(db,db.post,'%(summary)s')
>>
>>
>> So when i want the user to upload an image so it can be related to the
>> post i only want to show the posts in the form that the user owns.
>>
>> controller
>> ------------------
>> @auth.requires_login()
>> def newimage():
>> dbtable = db.uploads #uploads table name
>> if auth.is_logged_in:
>> dbtable.up_author.default = auth.user.id
>>
>> form = SQLFORM(dbtable)
>> return dict(form=form)
>>
>>
>> It has a few more lines but are for testing and practice as i am really
>> new to web2py :)
>>
>> That is all. Thanks for any advice.
>>
>> Cheers!
>>
>>
--
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.