Commit 0452e961 authored by Serge S. Koval's avatar Serge S. Koval

get_query() for ORM backends

parent 0c436e72
Changelog
=========
1.0.5
-----
1.0.4
-----
......
......@@ -4,6 +4,8 @@ Quick Start
This page gives quick introduction to Flask-Admin library. It is assumed that reader has some prior
knowledge of the `Flask <http://flask.pocoo.org/>`_ framework.
If you're Django user, you might also find :doc:`django_migration` guide helpful.
Introduction
------------
......@@ -24,14 +26,16 @@ Here is absolutely valid administrative piece::
def test(self):
return self.render('admin/test.html')
If user will hit `index` view, `admin/myindex.html` template will be rendered. Same for `test` view.
So, how does it help structuring administrative interface? With such building blocks, you're
implementing reusable functional pieces that are highly customizable.
For example, Flask-Admin provides ready-to-use SQLAlchemy model interface. It is implemented as a
class which accepts two parameters: model and a database session. While it exposes some
class which accepts two parameters: model class and a database session. While it exposes some
class-level variables which change behavior of the interface (somewhat similar to django.contrib.admin),
nothing prohibits you from overriding form creation logic, database access methods or extending existing
functionality.
nothing prohibits you from inheriting from it and override form creation logic, database access methods
or extend existing functionality by adding more views.
Initialization
--------------
......
......@@ -240,7 +240,7 @@ class ModelView(BaseModelView):
return form_class
def get_queryset(self):
def get_query(self):
"""
Returns the QuerySet for this view. By default, it returns all the
objects for the current model.
......@@ -265,7 +265,7 @@ class ModelView(BaseModelView):
:param execute:
Run query immediately or not
"""
query = self.get_queryset()
query = self.get_query()
# Filters
if self._filters:
......@@ -319,7 +319,7 @@ class ModelView(BaseModelView):
:param id:
Model ID
"""
return self.get_queryset().filter(pk=id).first()
return self.get_query().filter(pk=id).first()
def create_model(self, form):
"""
......@@ -393,7 +393,7 @@ class ModelView(BaseModelView):
count = 0
all_ids = [ObjectId(pk) for pk in ids]
for obj in self.get_queryset().in_bulk(all_ids).values():
for obj in self.get_query().in_bulk(all_ids).values():
obj.delete()
count += 1
......
......@@ -252,9 +252,12 @@ class ModelView(BaseModelView):
return query
def get_query(self):
return self.model.select()
def get_list(self, page, sort_column, sort_desc, search, filters,
execute=True):
query = self.model.select()
query = self.get_query()
joins = set()
......
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