steve schrieb:
> for my objects, i am trying to associate an user with each item.  to
> restrict users to their own items, one would typically add
> "filter(MyObjClass.user_id==request.identity["user"].user_id)" to all
> the queries.  could we enforce this from the model instead?  i feel
> like eventually someone would forget the extra filter statement.

Just add a class method to your mapped model class that runs the query
you want and use this in the controller. Example (untested):

class Items(object):
    @classmethod
    def user_items(cls, user=None):
        if user is None:
            user = request.identity['user']
        return session.query(cls).filter(cls.user_id=user.user_id)


and in your controller:

    @expose()
    def item_list(self):
        return dict(items=Items.user_items())


Chris

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to