Permalink
Browse files

#3 - Add SQAlchemy specific column_type_formatter

  • Loading branch information...
1 parent 7fb2d6b commit ac1c520233250a91d461fdaad4f2a36721d14450 @ArtemSerga ArtemSerga committed Dec 17, 2012
@@ -1,9 +1,8 @@
from mongoengine.base import BaseList
-
from flask.ext.admin.model.typefmt import DEFAULT_FORMATTERS
-def mongoengine_list_formatter(values):
+def list_formatter(values):
"""
Return string with comma separated values
@@ -13,7 +12,7 @@ def mongoengine_list_formatter(values):
return u', '.join(unicode(v) for v in values)
-MONGOENGINE_FORMATTERS = dict(DEFAULT_FORMATTERS)
-MONGOENGINE_FORMATTERS.update({
- BaseList: mongoengine_list_formatter
- })
+DEFAULT_FORMATTERS = DEFAULT_FORMATTERS.copy()
+DEFAULT_FORMATTERS.update({
+ BaseList: list_formatter
+})
@@ -12,7 +12,7 @@
from flask.ext.admin.form import BaseForm
from .filters import FilterConverter, BaseMongoEngineFilter
from .form import model_form, CustomModelConverter
-from .typefmt import MONGOENGINE_FORMATTERS
+from .typefmt import DEFAULT_FORMATTERS
from .tools import parse_like_term
@@ -76,7 +76,7 @@ class MyAdminView(ModelView):
Override this attribute to use non-default converter.
"""
- column_type_formatters = MONGOENGINE_FORMATTERS
+ column_type_formatters = DEFAULT_FORMATTERS
"""
Customized type formatters for MongoEngine backend
"""
@@ -0,0 +1,8 @@
+from flask.ext.admin.model.typefmt import DEFAULT_FORMATTERS, list_formatter
+from sqlalchemy.orm.collections import InstrumentedList
+
+
+DEFAULT_FORMATTERS = DEFAULT_FORMATTERS.copy()
+DEFAULT_FORMATTERS.update({
+ InstrumentedList: list_formatter
+})
@@ -13,6 +13,7 @@
from flask.ext.admin.actions import action
from flask.ext.admin.contrib.sqlamodel import form, filters, tools
+from .typefmt import DEFAULT_FORMATTERS
class ModelView(BaseModelView):
@@ -215,6 +216,8 @@ class MyModel1View(Base):
column_labels = {'models': 'Hello'}
"""
+ column_type_formatters = DEFAULT_FORMATTERS
+
def __init__(self, model, session,
name=None, category=None, endpoint=None, url=None):
"""

0 comments on commit ac1c520

Please sign in to comment.