Closed RealJTG closed 11 years ago
Not sure if bug: I have trouble with customization of complex fields through model_form
model_form
field_args = {'myfield': {'label': 'Custom label'}} works with db.StringField(), but have no effect with db.ListField(db.StringField())
field_args = {'myfield': {'label': 'Custom label'}}
db.StringField()
db.ListField(db.StringField())
import flask from flask.ext.mongoengine import MongoEngine from flask.ext.mongoengine.wtf import model_form from wtforms import widgets app = flask.Flask(__name__) app.config.from_object(__name__) app.config['MONGODB_SETTINGS'] = {'DB': 'testing'} app.config['SECRET_KEY'] = "foo" app.debug = True db = MongoEngine() db.init_app(app) class TestModel(db.Document): text = db.StringField() lst = db.ListField(db.StringField()) GenericForm = model_form(TestModel) CustomForm = model_form(TestModel, field_args = {'text': {'label': 'Custom label', 'widget': widgets.TextInput()}, 'lst': {'label': 'Custom label', 'widget': widgets.HiddenInput()}}) @app.route('/') def index(): document = TestModel.objects().first() generic_form = GenericForm(obj=document) custom_form = CustomForm(obj=document) return flask.render_template_string(""" Generic form: <br><br> {{ generic_form.text.label }} {{ generic_form.text }} <br> {{ generic_form.lst.label }} {{ generic_form.lst }} <br><br> Custom form: <br><br> This one has custom label and widget: <br> {{ custom_form.text.label }} {{ custom_form.text }} <br><br> But this - same as generic <br> {{ custom_form.lst.label }} {{ custom_form.lst }} """, generic_form=generic_form, custom_form=custom_form) if __name__ == "__main__": TestModel.objects().delete() TestModel(text="foo", lst=["bar"]).save() app.run(host="0.0.0.0", port=4000)
Added a hook so you can pass sub_field_args to FieldList
sub_field_args
Updated - just use a nested field_args
field_args
Not sure if bug: I have trouble with customization of complex fields through
model_form
field_args = {'myfield': {'label': 'Custom label'}}
works withdb.StringField()
, but have no effect withdb.ListField(db.StringField())