Skip to content

fix(peewee): support form_choices in Peewee ModelView#2853

Open
hasansezertasan wants to merge 7 commits into
masterfrom
fix/peewee-form-choices
Open

fix(peewee): support form_choices in Peewee ModelView#2853
hasansezertasan wants to merge 7 commits into
masterfrom
fix/peewee-form-choices

Conversation

@hasansezertasan

Copy link
Copy Markdown
Member

Summary

  • Override convert() in CustomModelConverter to check form_choices before delegating to wtfpeewee's default conversion, returning a Select2Field when choices are defined (matching the SQLAlchemy contrib behavior)
  • Add test for form_choices in the Peewee test suite
  • Add form_choices usage to the peewee_simple example

Fixes #2235

Test plan

  • pytest flask_admin/tests/peeweemodel/ — all 12 tests pass
  • Manual verification with peewee_simple example — status field renders as a Select2 dropdown

@hasansezertasan hasansezertasan force-pushed the fix/peewee-form-choices branch from 088044d to df74d47 Compare April 1, 2026 08:08
@hasansezertasan hasansezertasan marked this pull request as draft April 1, 2026 08:09
Override convert() in CustomModelConverter to check form_choices
before delegating to wtfpeewee's default conversion. When a field
has choices defined, return a Select2Field matching the behavior
of the SQLAlchemy contrib.

Respects form_overrides priority, builds kwargs with proper
validators and filters consistent with the parent converter.
@hasansezertasan hasansezertasan force-pushed the fix/peewee-form-choices branch from df74d47 to c29d873 Compare April 1, 2026 08:12
@hasansezertasan hasansezertasan force-pushed the fix/peewee-form-choices branch from c29d873 to 9968e0e Compare April 1, 2026 08:23
Delegate to the parent ModelConverter and reuse its built kwargs
(validators, filters, default, label, description) instead of
reconstructing them. Drops imports of wtfpeewee internals (FieldInfo,
handle_null_filter, ValueRequired) so future wtfpeewee changes to
validator/filter defaults propagate automatically.

Also add an integration test covering POST persistence and edit-form
pre-population for form_choices.
@hasansezertasan hasansezertasan requested review from ElLorans and samuelhwilliams and removed request for ElLorans June 14, 2026 14:16
@hasansezertasan hasansezertasan marked this pull request as ready for review June 14, 2026 14:17
@hasansezertasan hasansezertasan requested a review from ElLorans June 14, 2026 14:32
@ElLorans

Copy link
Copy Markdown
Contributor

This looks solid, but why can't we use the same convert function across the different orms? Maybe we can even upstream it to ModelConverter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

form_choices for flask_admin.contrib.peewee.ModelView doesn't work

2 participants