You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a suggested way to get a select field to play nicely with a column that uses a Enum type that is nullable?
Generally I want to use an Enum for possible values. But the column should allow null and the select list should have an empty option. I would like something like this:
This renders the select OK, but does not activate the 'selected' item in the select options.
Create my own SelectFieldNullable(SelectField), which behaves as a SelectField but also injects the option ("__None", "") as the QuerySelectField does.
As above this renders the select OK, but does not activate the 'selected' item in the select options.
QuerySelectField has an allow_blank option, which works well when the field is working off an ORM. But when using an Enum type, it gives errors.
File ".../lib/python3.10/site-packages/sqladmin/helpers.py", line 178, in get_primary_keys
return tuple(inspect(model).mapper.primary_key)
File ".../lib/python3.10/site-packages/sqlalchemy/inspection.py", line 147, in inspect
raise exc.NoInspectionAvailable(
sqlalchemy.exc.NoInspectionAvailable: No inspection system is available for object of type <enum 'FeeStructuresEnum'>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Is there a suggested way to get a select field to play nicely with a column that uses a Enum type that is nullable?
Generally I want to use an Enum for possible values. But the column should allow null and the select list should have an empty option. I would like something like this:
I have tried these things:
Create my own SelectFieldNullable(SelectField), which behaves as a SelectField but also injects the option ("__None", "") as the QuerySelectField does.
As above this renders the select OK, but does not activate the 'selected' item in the select options.
QuerySelectField has an allow_blank option, which works well when the field is working off an ORM. But when using an Enum type, it gives errors.
Beta Was this translation helpful? Give feedback.
All reactions