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

get_query() for ORM backends

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