Commit 4d79c706 authored by Tom Kedem's avatar Tom Kedem

Removed sqlalchemy-utils dependency.

Modified hybrid property example to make use of the scaffold mechanism to create filters.
parent 1187b8ea
...@@ -4,7 +4,6 @@ from sqlalchemy.ext.hybrid import hybrid_property ...@@ -4,7 +4,6 @@ from sqlalchemy.ext.hybrid import hybrid_property
import flask_admin as admin import flask_admin as admin
from flask_admin.contrib import sqla from flask_admin.contrib import sqla
from flask_admin.contrib.sqla.filters import IntGreaterFilter
# Create application # Create application
app = Flask(__name__) app = Flask(__name__)
...@@ -36,14 +35,13 @@ class Screen(db.Model): ...@@ -36,14 +35,13 @@ class Screen(db.Model):
class ScreenAdmin(sqla.ModelView): class ScreenAdmin(sqla.ModelView):
''' Flask-admin can not automatically find a hybrid_property yet. You will """ Flask-admin can not automatically find a hybrid_property yet. You will
need to manually define the column in list_view/filters/sorting/etc.''' need to manually define the column in list_view/filters/sorting/etc."""
list_columns = ['id', 'width', 'height', 'number_of_pixels'] list_columns = ['id', 'width', 'height', 'number_of_pixels']
column_sortable_list = ['id', 'width', 'height', 'number_of_pixels'] column_sortable_list = ['id', 'width', 'height', 'number_of_pixels']
# make sure the type of your filter matches your hybrid_property # Flask-admin can automatically detect the relevant filters for hybrid properties.
column_filters = [IntGreaterFilter(Screen.number_of_pixels, column_filters = ('number_of_pixels', )
'Number of Pixels')]
# Create admin # Create admin
......
from sqlalchemy import tuple_, or_, and_ from sqlalchemy import tuple_, or_, and_, inspect
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.sql.operators import eq from sqlalchemy.sql.operators import eq
from sqlalchemy.exc import DBAPIError from sqlalchemy.exc import DBAPIError
from sqlalchemy.orm.attributes import InstrumentedAttribute from sqlalchemy.orm.attributes import InstrumentedAttribute
from sqlalchemy_utils import get_hybrid_properties
from flask_admin._compat import filter_list, string_types from flask_admin._compat import filter_list, string_types
from flask_admin.tools import iterencode, iterdecode, escape from flask_admin.tools import iterencode, iterdecode, escape
...@@ -173,5 +173,14 @@ def get_field_with_path(model, name): ...@@ -173,5 +173,14 @@ def get_field_with_path(model, name):
return attr, path return attr, path
# copied from sqlalchemy-utils
def get_hybrid_properties(model):
return dict(
(key, prop)
for key, prop in inspect(model).all_orm_descriptors.items()
if isinstance(prop, hybrid_property)
)
def is_hybrid_property(model, attr_name): def is_hybrid_property(model, attr_name):
return attr_name in get_hybrid_properties(model) return attr_name in get_hybrid_properties(model)
Flask>=0.7 Flask>=0.7
wtforms wtforms
Flask-SQLAlchemy>=0.15 Flask-SQLAlchemy>=0.15
sqlalchemy-utils
peewee peewee
wtf-peewee wtf-peewee
pymongo==2.8 pymongo==2.8
......
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