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

Fix form_args default #756

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqladmin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _prepare_column(
if (column.primary_key or column.foreign_keys) and not form_include_pk:
return None

default = getattr(column, "default", None)
default = getattr(column, "default", None) or kwargs.get("default")

if default is not None:
# Only actually change default if it has an attribute named
Expand Down
3 changes: 2 additions & 1 deletion tests/test_forms/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,12 @@ async def test_model_form_exclude() -> None:


async def test_model_form_form_args() -> None:
form_args = {"name": {"label": "User Name"}}
form_args = {"name": {"label": "User Name"}, "number": {"default": 100}}
Form = await get_model_form(
model=User, session_maker=session_maker, form_args=form_args
)
assert Form()._fields["name"].label.text == "User Name"
assert Form()._fields["number"].default == 100


async def test_model_form_column_label() -> None:
Expand Down
Loading