A picture is worth a thousand words. Here’s what I’m trying to fix in Flask-Admin:
I’m trying to edit a field from the list view by including the field in the column_editable_list
of the model view. The field’s values come from another table via a foreign key relationship, so the user selects a value from the dropdown menu, which is not visible, I guess because there are too many columns in the view, so it’s squished?
Anybody know how to fix this without removing the other columns from the list view?
Here’s my model view (I’ve removed quite a few columns to simplify this a bit for StackOverflow):
JavaScript
x
22
22
1
class StructureView(MyModelView):
2
"""Flask-Admin view for Structure model (public.structures table)"""
3
4
can_create = True
5
can_edit = True
6
7
column_list = (
8
'structure',
9
'uno',
10
'egas',
11
'power_unit',
12
)
13
column_sortable_list = column_list
14
column_editable_list = column_list
15
16
column_labels = dict(
17
structure="Master Structure Serial",
18
uno="UNOGAS UNO",
19
egas="UNOGAS EGAS",
20
power_unit="Power Unit Serial",
21
)
22
Here’s the underlying SQLAlchemy model:
JavaScript
1
19
19
1
class Structure(db.Model):
2
"""Create a public.structures table representation"""
3
__tablename__ = 'structures'
4
5
id = db.Column(INTEGER, primary_key=True)
6
structure = db.Column(INTEGER, nullable=False, unique=True)
7
8
egas_id = db.Column(INTEGER, db.ForeignKey('public.egas.id'))
9
egas = relationship('Egas', back_populates='structures') # one-to-many
10
11
uno_id = db.Column(INTEGER, db.ForeignKey('public.uno.id'))
12
uno = relationship('Uno', back_populates='structures') # one-to-many
13
14
power_unit_id = db.Column(INTEGER, db.ForeignKey('public.power_units.id'))
15
power_unit = relationship('PowerUnit', back_populates='structures') # one-to-many
16
17
def __repr__(self):
18
return str(self.structure)
19
Thanks! Sean
Advertisement
Answer
I fixed the problem with custom CSS. Flask-Admin uses Select2 for form fields.
JavaScript
1
4
1
.select2-choices {
2
min-width: 200px;
3
}
4