Commit 005a4636 authored by PJ Janse van Rensburg's avatar PJ Janse van Rensburg

Tweak docstring for get_query and get_one

parent 07727643
......@@ -824,8 +824,6 @@ class ModelView(BaseModelView):
"""
Return a query for the model type.
If you override this method, don't forget to override `get_count_query` as well.
This method can be used to set a "persistent filter" on an index_view.
Example::
......@@ -834,16 +832,9 @@ class ModelView(BaseModelView):
def get_query(self):
return super(MyView, self).get_query().filter(User.username == current_user.username)
Individual elements that are filtered in the list view are still
accessible through the edit view by simply changing the URL, even
when they are filtered by `get_query`. To prohibit this, also
override `get_one`.
Example::
def get_one(self, id):
query = self.get_query()
return query.filter(self.model.id == id).first()
If you override this method, don't forget to also override `get_count_query`, for displaying the correct
item count in the list view, and `get_one`, which is used when retrieving records for the edit view.
"""
return self.session.query(self.model)
......@@ -1084,6 +1075,12 @@ class ModelView(BaseModelView):
"""
Return a single model by its id.
Example::
def get_one(self, id):
query = self.get_query()
return query.filter(self.model.id == id).one()
Also see `get_query` for how to filter the list view.
:param id:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment