See https://stackoverflow.com/a/52929692/440323.

On Saturday, October 20, 2018 at 3:30:07 PM UTC-4, mostwanted wrote:
>
> I can get registered users to view only what they post and not what others 
> post, below is the simple code i used. What i want now is how to get only 
> members of groups to view only what their group members post and not 
> members of other groups:
>
> *MODEL:*
> db.define_table('post',
>                 Field('body', 'text', requires=IS_NOT_EMPTY(), label='What 
> is on your mind'),
>                 Field('posted_on', 'datetime', default=request.now, 
> readable=False, writable=False),
>                 Field('posted_by', 'reference auth_user', default=auth.
> user_id, readable=False, writable=False))
>
>
> *CONTROLLER:*
> @auth.requires_login()
> def index():
>     form=SQLFORM(db.post)
>     if form.process().accepted:
>         response.flash=T('Entered')
>     return locals()
>
> @auth.requires_login()
> def details():
>     user=db.auth_user(auth.user_id)
>     if not user or not(user.id==auth.user_id): redirect(URL('index'))
>     details=db(db.post.posted_by==user.id).select(db.post.ALL)
>     return locals()
>
> *VIEWS*
>
> *index*
> {{extend 'layout.html'}}
>
> {{=form}}
> {{pass}}
>
> *details*:
> {{extend 'layout.html'}}
>
> {{for details in details:}}
> Infomation: {{=details.body}}<br />
> Date: {{=details.posted_on}}<br />
> Poster: {{=details.posted_by.first_name}}<br />
> <hr />
> {{pass}}
>  
> How can I change my *details controller* to be able to achieve the above 
> task?
>
> Regards:
>
> Mostwanted
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to