I have a webapp that allows users to create their own fields for visualization in a form later.
I have a Formfield model, for example:
class Formfield(db.Model): id = db.Column(db.Integer, primary_key = True) form_id = db.Column(db.Integer, db.ForeignKey('formbooking.id')) label = db.Column(db.String(80)) placeholder_text = db.Column(db.String(80)) help_text = db.Column(db.String(500)) box_checked = db.Column(db.Boolean, nullable = True, default = False) options = db.Column(db.String)
which I use to represent the field, regardless of type (checkbox, input, more in the future).
As you can see, each field has an FK for form_id.
Im trying to create a dynamic form for a given form_id. The catch is that I need to determine the type of field to render for each Formfield field. Therefore, I also need to process the field type at some point.
I assume that the solution must somehow pass the form_id to the function in my Form class.
I do not know how to do this or where to look for a solution.
Any help would be greatly appreciated!
python flask flask-wtforms sqlalchemy wtforms
Dailyrox
source share