Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use form_overrides on ListField(StringField)? #2409

Open
laiyonghao opened this issue Dec 30, 2023 · 0 comments
Open

How to use form_overrides on ListField(StringField)? #2409

laiyonghao opened this issue Dec 30, 2023 · 0 comments

Comments

@laiyonghao
Copy link

laiyonghao commented Dec 30, 2023

I have a WebPage class to store pages scraped from web.

class WebPage(Document):
    html = fields.StringField()
    top_image = fields.StringField()
    images = fields.ListField(fields.StringField())
    ... other fields.

I Defined a MyImageField to display image fields.

from wtforms import StringField
from wtforms.widgets import Input
from flask import render_template


class MyImageInputWidget(Input):
    def __call__(self, field, **kwargs):
        return render_template(
                "my_image_widget.html",
                field=field,
            )


class MyImageField(StringField):
    widget = MyImageInputWidget()

It is very easy to use with top_image field:

class WebPageModelView(ModelView):
    form_overrides = {
        'top_image': MyImageField,
    }

It looks like

image

But how to use form_overrides on images field ?

@laiyonghao laiyonghao changed the title How to use form_override on ListField(StringField)? How to use form_overrides on ListField(StringField)? Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants