I'm working on a app with RBAC and I'm trying to populate a QuerySelectField with data from my Role database model but it doesn't work because I'm constantly getting one of those two errors:
sqlalchemy.exc.OperationalError: <unprintable OperationalError object>
or
TypeError: 'BaseQuery' object is not callable
models.py
class Role(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement='auto')
name = db.Column(db.String(50), unique=True)
user = db.relationship('User', backref='role', lazy='dynamic')
not_view = db.Column(db.Text, nullable=False)
not_edit = db.Column(db.Text, nullable=False)
not_add = db.Column(db.Text, nullable=False)
not_delete = db.Column(db.Text, nullable=False)
forms.py
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField
from wtforms.validators import DataRequired, Email, EqualTo, Length
from app.models import Role
from wtforms.ext.sqlalchemy.fields import QuerySelectField
def role_choice():
return Role.query
class AddUserForm(FlaskForm):
username = StringField('Username', validators=[DataRequired(), Length(min=2, max=20)])
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('password')])
role_id = QuerySelectField(query_factory=role_choice)
I tried a few different ways of passing in data but none of them worked. Can someone help?