question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

column_editable_list doesn't support SelectField

See original GitHub issue

Here is my code for user model


class UserView(ModelView):
    column_editable_list = ('username', 'email', 'status')

    form_overrides = dict(
        status=SelectField
    )
    form_args = dict(
        status=dict(
            choices=[
                ('ACTIVE', 'ACTIVE'),
                ('DELETED', 'DELETED'),
                ('BLOCKED', 'BLOCKED')
            ]
        )
    )

On removing ‘status’ from column_editable_list, it works fine (for username and email), otherwise we get Exception: Unsupported field type: <class 'wtforms.fields.core.SelectField'>

how do I solve this?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
revircommented, Aug 26, 2016

@subhamagr Sorry, I tried to use Select2Field, avoid ‘Unsupported field type’, but failed to set choices. But for me, I use peewee, give choices in the model class:

JobStatus = (('Pending', 'Pending'),
               ('Running', 'Running'),
               ('Done', 'Done'),
               ('Failed', 'Failed'))

class Job(db.Model):
    session = CharField()
    status = CharField(default='Pending', choices=JobStatus)

Then override the XEditableWidget to support peewee’s SelectChoicesField:

from flask_admin.model.widgets import XEditableWidget
class MyFixedWidget(XEditableWidget):
    def get_kwargs(self, subfield, kwargs):
        if subfield.type == 'SelectChoicesField':
            kwargs['data-type'] = 'select'
            choices = [{'value': x, 'text': y} for x, y in subfield.choices]

            # prepend a blank field to choices if allow_blank = True
            if getattr(subfield, 'allow_blank', False):
                choices.insert(0, {'value': '__None', 'text': ''})

            # json.dumps fixes issue with unicode strings not loading correctly
            kwargs['data-source'] = json.dumps(choices)
            return kwargs
        else:
            return super().get_kwargs(subfield, kwargs)

Finally in my admin view, use my fixed widget to scaffold list view:

class JobView(ModelView):
    # fix SelectChoiceField in inline edit form.
    def get_list_form(self):
        return self.scaffold_list_form(widget=MyFixedWidget())

The way to override the list view field, see the document: http://flask-admin.readthedocs.io/en/latest/api/mod_model/?highlight=column_exclude_list#flask_admin.model.BaseModelView.get_list_form

If this can’t help you, we can discuss further.

0reactions
caffeinatedMikecommented, Oct 19, 2021

@mrjoes This issue can be closed (per #1742, it is resolved)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Edit a list column - Microsoft Support
Hover and click the down arrow on any of the list headings, and then click Column settings>Show/hide columns. click the down arrow on...
Read more >
Restricted access to dropdown column - Submit an Idea
I have a dropdown column and I want to restrict the permission to edit the options, but keep users enabled to select the...
Read more >
jqgrid incorrect select drop down option values in edit box
When I edit a record which contained Country id=2 (UK) and State id=6 (Oxford) , the edit form will shows correctly - Country...
Read more >
Solved: How do I edit the columns in a list view as an adm...
Any user that has made changes will have to click the gear on their list view and then select Reset to Column defaults...
Read more >
Excel drop down list: how to create, edit, copy and remove
If you select the whole column, a drop down menu will be created in each cell ... the In-cell dropdown box is checked;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found