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

ModelView ignoring viewonly on relationship #1680

Open
cancan101 opened this issue Jul 25, 2018 · 1 comment
Open

ModelView ignoring viewonly on relationship #1680

cancan101 opened this issue Jul 25, 2018 · 1 comment

Comments

@cancan101
Copy link

I have a relationship marked viewonly however the edit form for the ModelView still seems to render this field.

@ljluestc
Copy link


from flask_admin.contrib.sqla import ModelView
from your_module import YourModel

class CustomModelView(ModelView):
    # Override form_columns to exclude view-only relationships
    def scaffold_form(self):
        form_class = super().scaffold_form()
        if hasattr(self.model, '__viewonly__'):
            for field_name in self.model.__viewonly__:
                if hasattr(form_class, field_name):
                    delattr(form_class, field_name)
        return form_class

admin.add_view(CustomModelView(YourModel))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants