Open adorsett opened 1 year ago
This workaround worked. https://stackoverflow.com/a/51858425/15231085
Once I defined enum_field_options()
I had to manually add the field using SelectField.
category = SelectField("Category", **enum_field_options(Category))
Using Flask, SQLAlchemy, WTForms against an MySQL DB.
Imports
Have an Enumerated Type Field that's stored in MySQL as a native Enum Column
Model Definition
Setting up Globals
Use ModelForm to Auto-Build Form
Flask Handler Snippet
The Form in the HTML Template
The Form will show perfectly using the above template when selecting a pre-existing DB entry by ID. If I try to "Edit" that entry by simply clicking "Save" I get the following traceback.
I added a len() method to the Enum object and that cleared the Traceback but then I get a data validation error when calling form.validate().
This works but I want my Enum definitions stored in a central place and not in the middle of my Model definition: