Commit ea3322a0 authored by Serge S. Koval's avatar Serge S. Koval

Inline field list type customizations

parent 1fdfd3f3
...@@ -11,8 +11,8 @@ Introduction ...@@ -11,8 +11,8 @@ Introduction
Flask-Admin is advanced, extensible and simple to use administrative interface building extension for Flask framework. Flask-Admin is advanced, extensible and simple to use administrative interface building extension for Flask framework.
It comes with batteries included: model scaffolding for `SQLAlchemy <http://www.sqlalchemy.org/>`_, It comes with batteries included: model scaffolding for `SQLAlchemy <http://www.sqlalchemy.org/>`_,
`MongoEngine <http://mongoengine.org/>`_, MongoDB and `Peewee <https://github.com/coleifer/peewee>`_ ORMs, simple `MongoEngine <http://mongoengine.org/>`_, `pymongo <http://api.mongodb.org/python/current/>`_ and `Peewee <https://github.com/coleifer/peewee>`_ ORMs, simple
file management interface and a lot of usage samples. file management interface and a lot of usage examples.
You're not limited by the default functionality - instead of providing simple scaffolding for the ORM You're not limited by the default functionality - instead of providing simple scaffolding for the ORM
models, Flask-Admin provides tools that can be used to construct administrative interfaces of any complexity, models, Flask-Admin provides tools that can be used to construct administrative interfaces of any complexity,
......
...@@ -17,6 +17,7 @@ class CustomModelConverter(orm.ModelConverter): ...@@ -17,6 +17,7 @@ class CustomModelConverter(orm.ModelConverter):
Injects various Flask-Admin widgets and handles lists with Injects various Flask-Admin widgets and handles lists with
customized InlineFieldList field. customized InlineFieldList field.
""" """
def __init__(self, view): def __init__(self, view):
super(CustomModelConverter, self).__init__() super(CustomModelConverter, self).__init__()
......
...@@ -95,6 +95,18 @@ class CustomModelConverter(ModelConverter): ...@@ -95,6 +95,18 @@ class CustomModelConverter(ModelConverter):
class InlineModelConverter(InlineModelConverterBase): class InlineModelConverter(InlineModelConverterBase):
"""
Inline model form helper.
"""
inline_field_list_type = InlineModelFormList
"""
Used field list type.
If you want to do some custom rendering of inline field lists,
you can create your own wtforms field and use it instead
"""
def get_info(self, p): def get_info(self, p):
info = super(InlineModelConverter, self).get_info(p) info = super(InlineModelConverter, self).get_info(p)
...@@ -155,11 +167,11 @@ class InlineModelConverter(InlineModelConverterBase): ...@@ -155,11 +167,11 @@ class InlineModelConverter(InlineModelConverterBase):
setattr(form_class, setattr(form_class,
prop_name, prop_name,
InlineModelFormList(child_form, self.inline_field_list_type(child_form,
info.model, info.model,
reverse_field.name, reverse_field.name,
info, info,
label=label or info.model.__name__)) label=label or info.model.__name__))
setattr(field.rel_model, setattr(field.rel_model,
prop_name, prop_name,
......
...@@ -380,6 +380,15 @@ class InlineModelConverter(InlineModelConverterBase): ...@@ -380,6 +380,15 @@ class InlineModelConverter(InlineModelConverterBase):
""" """
Inline model form helper. Inline model form helper.
""" """
inline_field_list_type = InlineModelFormList
"""
Used field list type.
If you want to do some custom rendering of inline field lists,
you can create your own wtforms field and use it instead
"""
def __init__(self, session, view): def __init__(self, session, view):
super(InlineModelConverter, self).__init__(view) super(InlineModelConverter, self).__init__(view)
self.session = session self.session = session
...@@ -488,11 +497,11 @@ class InlineModelConverter(InlineModelConverterBase): ...@@ -488,11 +497,11 @@ class InlineModelConverter(InlineModelConverterBase):
# Contribute field # Contribute field
setattr(form_class, setattr(form_class,
forward_prop.key, forward_prop.key,
InlineModelFormList(child_form, self.inline_field_list_type(child_form,
self.session, self.session,
info.model, info.model,
reverse_prop.key, reverse_prop.key,
info, info,
**kwargs)) **kwargs))
return form_class return form_class
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