kashifpk / PyCK

Python Code Karigar - A web framework aimed at being easy to use and powerful
http://pyck.compulife.com.pk
Other
4 stars 0 forks source link

Default filter condition for CRUD interface #59

Closed kashifpk closed 9 years ago

kashifpk commented 9 years ago

Allow specifying a default SQLAlchemy filter condition for CRUD interface. The condition could be anything that can be fit into SQLAlchemy's filter method for a query. For example:

default_filter = User.user_id == request.session['logged_in_user_id']
kashifpk commented 9 years ago

Upon implementation, this works:

list_filter_condition = {
    SensorReading.__name__: "self.model.user_id == self.request.session.get('logged_in_user', '')"
}

Need to provide the whole thing as string which is passed to python's eval function. Also to access the model, don't use the model's class name (in this case SensorReading) since that is not directly accessible inside the crud controller, instead ues self.model