pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
https://flask-admin.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5.76k stars 1.57k forks source link

Form column is not being displayed if it starts with underscore "_" #2419

Closed princerb closed 6 months ago

princerb commented 6 months ago

if I set form_columns to ('name', '_surname'), it only displays name in the form page, leaving other columns that starts with the underscore "_" in its name.

Example:

class MyModelView(ModelView):
    column_list = ('name', '_surname')
    form_columns = ('name', '_surname')

Model would look like this (SQLAlchemy):

class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String(100), nullable=False)
    _surname = Column(String(100), nullable=False)

So, in the form pages (edit, create) of the user, input fields of the columns those start with "_" will not be rendered in html page.

Hope, you found it a new noticable thing!

princerb commented 6 months ago

Could someone please explain this? 🤔

Acrofil commented 6 months ago

I think this is because the convention is to hide attributes that start with "_" (private). Maybe there is a way to expose it, but best will be to rename it to "surname".

princerb commented 6 months ago

It can't be renamed in some cases, so I think there should be a force command to implement it for certain situations.

wojtect commented 6 months ago

Have you tried setting ignore_hidden?

class MyModelView(ModelView):
    ignore_hidden = False

https://github.com/flask-admin/flask-admin/blob/14e24c970f0ee3a29add830612eee9a0b0ba5dcc/flask_admin/contrib/sqla/view.py#L291-L299

princerb commented 6 months ago

I just tried ignore_hidden, but didn't work, and I guess that setting does not apparently work or has some bugs.

princerb commented 6 months ago

Almost duplicate of #1541

princerb commented 6 months ago

Not a Flask-Admin issue.