Created
July 21, 2012 09:58
-
-
Save mkuprionis/3155322 to your computer and use it in GitHub Desktop.
Flask-Restless with URL rules example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# flask-restless.views.API | |
class API(ModelView): | |
def get(self, instid, **kwargs): | |
<...> | |
self._search(**kwargs) | |
<...> | |
def _search(self, **kwargs): | |
<...> | |
self._before_search(data, **kwargs) | |
<...> | |
# Extending class | |
class ItemAPI(API): | |
def _before_search(data, user_id, **kwargs): | |
data['filters'].append({ | |
'name': 'owner_id', | |
'op': 'equals', | |
'val': user_id | |
}) | |
return True | |
# Actual API | |
manager.create_api( | |
Item, | |
methods=['GET', 'POST', 'PUT', 'DELETE'], | |
api_class=ItemAPI, | |
collection_name='/user/<int:user_id>/items') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment