-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow model columns to bear the same name as reserved WTForms attributes
For example, a Model with a mapped column named `data` would collide with the [`wtforms.Form.data`](https://github.com/aminalaee/sqladmin/blob/main/sqladmin/forms.py#L619-L634) property, which would generate errors when processing or rendering the form. What we do here is silently rename the column when entering and leaving WTForms territory. Taking the example of a column named `data`, the associated `Field` object will: - be listed under the form key `data_` - be passed a `name='data'` kwarg so that it is still displayed with the `data` label in the admin web UI Instead of directly passing `form.data` to `model_view.insert_model` or `model_view.update_model`, we first restore the original name (e.g. `data_` to `data`) so that the underlying SQLAlchemy can them work on the originalcolumn. > **Note**: this is a bit crude and I think the naming could be improved. Feel free to refactor at will. Fixes #656
- Loading branch information
Showing
4 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters