WTForms checkbox field not populatingCreate a custom field in wtFormsDecimal field rounding in WTFormsflask-wtforms field requiredFlask WTForms - Dynamic BooleanField from databaseUsing HTML5 fields with WTFormspopulate WTForms select field using value selected from previous fieldImport checkbox value from databaseDynamic WTForm field is not validatedFlask-WTForms and hidden fieldsWTForms / SQLAlchemy field validation
Have I saved too much for retirement so far?
How to be able to process a large JSON response?
Pronouncing Homer as in modern Greek
My boss asked me to take a one-day class, then signs it up as a day off
Partial sums of primes
Can the harmonic series explain the origin of the major scale?
Calculating the number of days between 2 dates in Excel
Is there an Impartial Brexit Deal comparison site?
Identify a stage play about a VR experience in which participants are encouraged to simulate performing horrific activities
Can I rely on these GitHub repository files?
How did Monica know how to operate Carol's "designer"?
The most efficient algorithm to find all possible integer pairs which sum to a given integer
Simple image editor tool to draw a simple box/rectangle in an existing image
What would you call a finite collection of unordered objects that are not necessarily distinct?
A Standard Integral Equation
Should my PhD thesis be submitted under my legal name?
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
Why are on-board computers allowed to change controls without notifying the pilots?
What will be the benefits of Brexit?
When is separating the total wavefunction into a space part and a spin part possible?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
How will losing mobility of one hand affect my career as a programmer?
Java - What do constructor type arguments mean when placed *before* the type?
Giant Toughroad SLR 2 for 200 miles in two days, will it make it?
WTForms checkbox field not populating
Create a custom field in wtFormsDecimal field rounding in WTFormsflask-wtforms field requiredFlask WTForms - Dynamic BooleanField from databaseUsing HTML5 fields with WTFormspopulate WTForms select field using value selected from previous fieldImport checkbox value from databaseDynamic WTForm field is not validatedFlask-WTForms and hidden fieldsWTForms / SQLAlchemy field validation
I'm fairly new to Python & Flask in general, but I'm having an issue with checkboxes that I can't figure out. Database field is an Integer (SQLite). When I create a record, it works with 1 or 0. However, when I try to edit a record using WTForms, I can't get the checkbox to reflect what is in the database - 1 or 0 (Checked or Unchecked). The fields in question below are manager, dept_head, and admin. Not sure what I'm missing? Any suggestions would be greatly appreciated.
- Apologies for the wall of text, but wanted to make sure I didn't leave anything out.
Model
class User(UserMixin, db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
firstname = db.Column(db.String(128), nullable=False)
lastname = db.Column(db.String(128), nullable=False)
email = db.Column(db.String(128), nullable=False)
password_hash = db.Column(db.String(128), nullable=True)
locationid = db.Column(db.Integer, db.ForeignKey('locations.id'), nullable=True)
location = db.relationship('Location', backref='users')
departmentid = db.Column(db.Integer, db.ForeignKey('departments.id'), nullable=True)
department = db.relationship('Department', backref='users')
job_title = db.Column(db.String(128), nullable=True)
mobile_phone = db.Column(db.String(16), nullable=False)
manager = db.Column(db.Integer, nullable=False, default=0)
dept_head = db.Column(db.Integer, nullable=False, default=0)
admin = db.Column(db.Integer, nullable=False, default=0)
date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
date_updated = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
date_deleted = db.Column(db.DateTime)
Form
class UserForm(FlaskForm):
id = HiddenField('ID')
firstname = StringField('First Name', validators=[DataRequired()])
lastname = StringField('Last Name', validators=[DataRequired()])
email = StringField('Email', validators=[DataRequired(), Email()])
locationid = SelectField('Location')
departmentid = SelectField('Department')
job_title = StringField('Job Title')
mobile_phone = StringField('Mobile Phone', validators=[DataRequired()])
manager = BooleanField('Manager', default=False, false_values=(False, 'false', 0, '0'))
dept_head = BooleanField('Dept Head', default=False, false_values=(False, 'false', 0, '0'))
admin = BooleanField('Admin', default=False, false_values=(False, 'false', 0, '0'))
submit = SubmitField('Create')
def __init__(self, *args, **kwargs):
super(UserForm, self).__init__()
self.locationid.choices = [(l.id, l.name) for l in Location.query.all()]
self.departmentid.choices = [(d.id, d.name) for d in Department.query.all()]
Controller
@mod_user.route('/edit/<int:id>', methods=['GET', 'POST'])
@login_required
def edit(id):
u = User.query.filter_by(id=id).first_or_404()
form = UserForm()
form.process(formdata=request.form, obj=u)
return render_template('user/edit.html', form=form, u = u)
Edit.html
<form method="POST" action=" url_for('user.update', id=u.id) " accept-charset="UTF-8" role="form" id="UserForm">
form.csrf_token
form.id
<p><label>First Name: </label> form.firstname(class_='form-control') </p>
<p><label>Last Name: </label> form.lastname(class_='form-control') </p>
<p><label>Email: </label> form.email(class_='form-control') </p>
<p><label>Location: </label> form.locationid(class_='form-control') </p>
<p><label>Dept: </label> form.departmentid(class_='form-control') </p>
<p><label>Job Title: </label> form.job_title(class_='form-control') </p>
<p><label>Mobile Phone: </label> form.mobile_phone(class='form-control', placeholder='(555) 555-1212') </p>
<p><label>Manager: </label> form.manager(class_='fancy-checkbox', value=1) </p>
<p><label>Dept Head: </label> form.dept_head(class_='fancy-checkbox', value=1) </p>
<p><label>Admin: </label> form.admin(class_='fancy-checkbox', value=1) </p>
form.submit(class_='btn btn-primary btn-lg')
</form>
Data
Database
Form in Action (Admin user example, all should be checked)
Web Form
python flask-wtforms
add a comment |
I'm fairly new to Python & Flask in general, but I'm having an issue with checkboxes that I can't figure out. Database field is an Integer (SQLite). When I create a record, it works with 1 or 0. However, when I try to edit a record using WTForms, I can't get the checkbox to reflect what is in the database - 1 or 0 (Checked or Unchecked). The fields in question below are manager, dept_head, and admin. Not sure what I'm missing? Any suggestions would be greatly appreciated.
- Apologies for the wall of text, but wanted to make sure I didn't leave anything out.
Model
class User(UserMixin, db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
firstname = db.Column(db.String(128), nullable=False)
lastname = db.Column(db.String(128), nullable=False)
email = db.Column(db.String(128), nullable=False)
password_hash = db.Column(db.String(128), nullable=True)
locationid = db.Column(db.Integer, db.ForeignKey('locations.id'), nullable=True)
location = db.relationship('Location', backref='users')
departmentid = db.Column(db.Integer, db.ForeignKey('departments.id'), nullable=True)
department = db.relationship('Department', backref='users')
job_title = db.Column(db.String(128), nullable=True)
mobile_phone = db.Column(db.String(16), nullable=False)
manager = db.Column(db.Integer, nullable=False, default=0)
dept_head = db.Column(db.Integer, nullable=False, default=0)
admin = db.Column(db.Integer, nullable=False, default=0)
date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
date_updated = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
date_deleted = db.Column(db.DateTime)
Form
class UserForm(FlaskForm):
id = HiddenField('ID')
firstname = StringField('First Name', validators=[DataRequired()])
lastname = StringField('Last Name', validators=[DataRequired()])
email = StringField('Email', validators=[DataRequired(), Email()])
locationid = SelectField('Location')
departmentid = SelectField('Department')
job_title = StringField('Job Title')
mobile_phone = StringField('Mobile Phone', validators=[DataRequired()])
manager = BooleanField('Manager', default=False, false_values=(False, 'false', 0, '0'))
dept_head = BooleanField('Dept Head', default=False, false_values=(False, 'false', 0, '0'))
admin = BooleanField('Admin', default=False, false_values=(False, 'false', 0, '0'))
submit = SubmitField('Create')
def __init__(self, *args, **kwargs):
super(UserForm, self).__init__()
self.locationid.choices = [(l.id, l.name) for l in Location.query.all()]
self.departmentid.choices = [(d.id, d.name) for d in Department.query.all()]
Controller
@mod_user.route('/edit/<int:id>', methods=['GET', 'POST'])
@login_required
def edit(id):
u = User.query.filter_by(id=id).first_or_404()
form = UserForm()
form.process(formdata=request.form, obj=u)
return render_template('user/edit.html', form=form, u = u)
Edit.html
<form method="POST" action=" url_for('user.update', id=u.id) " accept-charset="UTF-8" role="form" id="UserForm">
form.csrf_token
form.id
<p><label>First Name: </label> form.firstname(class_='form-control') </p>
<p><label>Last Name: </label> form.lastname(class_='form-control') </p>
<p><label>Email: </label> form.email(class_='form-control') </p>
<p><label>Location: </label> form.locationid(class_='form-control') </p>
<p><label>Dept: </label> form.departmentid(class_='form-control') </p>
<p><label>Job Title: </label> form.job_title(class_='form-control') </p>
<p><label>Mobile Phone: </label> form.mobile_phone(class='form-control', placeholder='(555) 555-1212') </p>
<p><label>Manager: </label> form.manager(class_='fancy-checkbox', value=1) </p>
<p><label>Dept Head: </label> form.dept_head(class_='fancy-checkbox', value=1) </p>
<p><label>Admin: </label> form.admin(class_='fancy-checkbox', value=1) </p>
form.submit(class_='btn btn-primary btn-lg')
</form>
Data
Database
Form in Action (Admin user example, all should be checked)
Web Form
python flask-wtforms
Why did you define admin and dept_head as integers and not as booleans? docs.sqlalchemy.org/en/latest/core/…
– Pax Vobiscum
Mar 21 at 14:58
Because SQLite doesn't have a boolean datatype per their v3 documentation - unless I'm reading it wrong? New to SQLite also, so that could be the issue.
– tnoe
Mar 21 at 15:47
You can absolutely declare it as db.Boolean, however under the hood it is still an integer. But this will tell python to deal with the field as True/False
– Pax Vobiscum
Mar 21 at 15:53
The first link I posted comes from SQLAlchemy's own docs, this is from flask-sqlalchemy flask-sqlalchemy.pocoo.org/2.3/models
– Pax Vobiscum
Mar 21 at 15:55
Ok - that makes sense, thank you. I've changed them to db.Boolean, and it works in the console sending True, True, True when creating a User object. But when I do it through Edit.html, I get an typeError: '1' is not a boolean value. Have tried value=1 and value=True on the checkbox field. Seems that it's sending value=True or value=1 as a string?
– tnoe
Mar 21 at 16:24
add a comment |
I'm fairly new to Python & Flask in general, but I'm having an issue with checkboxes that I can't figure out. Database field is an Integer (SQLite). When I create a record, it works with 1 or 0. However, when I try to edit a record using WTForms, I can't get the checkbox to reflect what is in the database - 1 or 0 (Checked or Unchecked). The fields in question below are manager, dept_head, and admin. Not sure what I'm missing? Any suggestions would be greatly appreciated.
- Apologies for the wall of text, but wanted to make sure I didn't leave anything out.
Model
class User(UserMixin, db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
firstname = db.Column(db.String(128), nullable=False)
lastname = db.Column(db.String(128), nullable=False)
email = db.Column(db.String(128), nullable=False)
password_hash = db.Column(db.String(128), nullable=True)
locationid = db.Column(db.Integer, db.ForeignKey('locations.id'), nullable=True)
location = db.relationship('Location', backref='users')
departmentid = db.Column(db.Integer, db.ForeignKey('departments.id'), nullable=True)
department = db.relationship('Department', backref='users')
job_title = db.Column(db.String(128), nullable=True)
mobile_phone = db.Column(db.String(16), nullable=False)
manager = db.Column(db.Integer, nullable=False, default=0)
dept_head = db.Column(db.Integer, nullable=False, default=0)
admin = db.Column(db.Integer, nullable=False, default=0)
date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
date_updated = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
date_deleted = db.Column(db.DateTime)
Form
class UserForm(FlaskForm):
id = HiddenField('ID')
firstname = StringField('First Name', validators=[DataRequired()])
lastname = StringField('Last Name', validators=[DataRequired()])
email = StringField('Email', validators=[DataRequired(), Email()])
locationid = SelectField('Location')
departmentid = SelectField('Department')
job_title = StringField('Job Title')
mobile_phone = StringField('Mobile Phone', validators=[DataRequired()])
manager = BooleanField('Manager', default=False, false_values=(False, 'false', 0, '0'))
dept_head = BooleanField('Dept Head', default=False, false_values=(False, 'false', 0, '0'))
admin = BooleanField('Admin', default=False, false_values=(False, 'false', 0, '0'))
submit = SubmitField('Create')
def __init__(self, *args, **kwargs):
super(UserForm, self).__init__()
self.locationid.choices = [(l.id, l.name) for l in Location.query.all()]
self.departmentid.choices = [(d.id, d.name) for d in Department.query.all()]
Controller
@mod_user.route('/edit/<int:id>', methods=['GET', 'POST'])
@login_required
def edit(id):
u = User.query.filter_by(id=id).first_or_404()
form = UserForm()
form.process(formdata=request.form, obj=u)
return render_template('user/edit.html', form=form, u = u)
Edit.html
<form method="POST" action=" url_for('user.update', id=u.id) " accept-charset="UTF-8" role="form" id="UserForm">
form.csrf_token
form.id
<p><label>First Name: </label> form.firstname(class_='form-control') </p>
<p><label>Last Name: </label> form.lastname(class_='form-control') </p>
<p><label>Email: </label> form.email(class_='form-control') </p>
<p><label>Location: </label> form.locationid(class_='form-control') </p>
<p><label>Dept: </label> form.departmentid(class_='form-control') </p>
<p><label>Job Title: </label> form.job_title(class_='form-control') </p>
<p><label>Mobile Phone: </label> form.mobile_phone(class='form-control', placeholder='(555) 555-1212') </p>
<p><label>Manager: </label> form.manager(class_='fancy-checkbox', value=1) </p>
<p><label>Dept Head: </label> form.dept_head(class_='fancy-checkbox', value=1) </p>
<p><label>Admin: </label> form.admin(class_='fancy-checkbox', value=1) </p>
form.submit(class_='btn btn-primary btn-lg')
</form>
Data
Database
Form in Action (Admin user example, all should be checked)
Web Form
python flask-wtforms
I'm fairly new to Python & Flask in general, but I'm having an issue with checkboxes that I can't figure out. Database field is an Integer (SQLite). When I create a record, it works with 1 or 0. However, when I try to edit a record using WTForms, I can't get the checkbox to reflect what is in the database - 1 or 0 (Checked or Unchecked). The fields in question below are manager, dept_head, and admin. Not sure what I'm missing? Any suggestions would be greatly appreciated.
- Apologies for the wall of text, but wanted to make sure I didn't leave anything out.
Model
class User(UserMixin, db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
firstname = db.Column(db.String(128), nullable=False)
lastname = db.Column(db.String(128), nullable=False)
email = db.Column(db.String(128), nullable=False)
password_hash = db.Column(db.String(128), nullable=True)
locationid = db.Column(db.Integer, db.ForeignKey('locations.id'), nullable=True)
location = db.relationship('Location', backref='users')
departmentid = db.Column(db.Integer, db.ForeignKey('departments.id'), nullable=True)
department = db.relationship('Department', backref='users')
job_title = db.Column(db.String(128), nullable=True)
mobile_phone = db.Column(db.String(16), nullable=False)
manager = db.Column(db.Integer, nullable=False, default=0)
dept_head = db.Column(db.Integer, nullable=False, default=0)
admin = db.Column(db.Integer, nullable=False, default=0)
date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
date_updated = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
date_deleted = db.Column(db.DateTime)
Form
class UserForm(FlaskForm):
id = HiddenField('ID')
firstname = StringField('First Name', validators=[DataRequired()])
lastname = StringField('Last Name', validators=[DataRequired()])
email = StringField('Email', validators=[DataRequired(), Email()])
locationid = SelectField('Location')
departmentid = SelectField('Department')
job_title = StringField('Job Title')
mobile_phone = StringField('Mobile Phone', validators=[DataRequired()])
manager = BooleanField('Manager', default=False, false_values=(False, 'false', 0, '0'))
dept_head = BooleanField('Dept Head', default=False, false_values=(False, 'false', 0, '0'))
admin = BooleanField('Admin', default=False, false_values=(False, 'false', 0, '0'))
submit = SubmitField('Create')
def __init__(self, *args, **kwargs):
super(UserForm, self).__init__()
self.locationid.choices = [(l.id, l.name) for l in Location.query.all()]
self.departmentid.choices = [(d.id, d.name) for d in Department.query.all()]
Controller
@mod_user.route('/edit/<int:id>', methods=['GET', 'POST'])
@login_required
def edit(id):
u = User.query.filter_by(id=id).first_or_404()
form = UserForm()
form.process(formdata=request.form, obj=u)
return render_template('user/edit.html', form=form, u = u)
Edit.html
<form method="POST" action=" url_for('user.update', id=u.id) " accept-charset="UTF-8" role="form" id="UserForm">
form.csrf_token
form.id
<p><label>First Name: </label> form.firstname(class_='form-control') </p>
<p><label>Last Name: </label> form.lastname(class_='form-control') </p>
<p><label>Email: </label> form.email(class_='form-control') </p>
<p><label>Location: </label> form.locationid(class_='form-control') </p>
<p><label>Dept: </label> form.departmentid(class_='form-control') </p>
<p><label>Job Title: </label> form.job_title(class_='form-control') </p>
<p><label>Mobile Phone: </label> form.mobile_phone(class='form-control', placeholder='(555) 555-1212') </p>
<p><label>Manager: </label> form.manager(class_='fancy-checkbox', value=1) </p>
<p><label>Dept Head: </label> form.dept_head(class_='fancy-checkbox', value=1) </p>
<p><label>Admin: </label> form.admin(class_='fancy-checkbox', value=1) </p>
form.submit(class_='btn btn-primary btn-lg')
</form>
Data
Database
Form in Action (Admin user example, all should be checked)
Web Form
python flask-wtforms
python flask-wtforms
asked Mar 21 at 14:37
tnoetnoe
61
61
Why did you define admin and dept_head as integers and not as booleans? docs.sqlalchemy.org/en/latest/core/…
– Pax Vobiscum
Mar 21 at 14:58
Because SQLite doesn't have a boolean datatype per their v3 documentation - unless I'm reading it wrong? New to SQLite also, so that could be the issue.
– tnoe
Mar 21 at 15:47
You can absolutely declare it as db.Boolean, however under the hood it is still an integer. But this will tell python to deal with the field as True/False
– Pax Vobiscum
Mar 21 at 15:53
The first link I posted comes from SQLAlchemy's own docs, this is from flask-sqlalchemy flask-sqlalchemy.pocoo.org/2.3/models
– Pax Vobiscum
Mar 21 at 15:55
Ok - that makes sense, thank you. I've changed them to db.Boolean, and it works in the console sending True, True, True when creating a User object. But when I do it through Edit.html, I get an typeError: '1' is not a boolean value. Have tried value=1 and value=True on the checkbox field. Seems that it's sending value=True or value=1 as a string?
– tnoe
Mar 21 at 16:24
add a comment |
Why did you define admin and dept_head as integers and not as booleans? docs.sqlalchemy.org/en/latest/core/…
– Pax Vobiscum
Mar 21 at 14:58
Because SQLite doesn't have a boolean datatype per their v3 documentation - unless I'm reading it wrong? New to SQLite also, so that could be the issue.
– tnoe
Mar 21 at 15:47
You can absolutely declare it as db.Boolean, however under the hood it is still an integer. But this will tell python to deal with the field as True/False
– Pax Vobiscum
Mar 21 at 15:53
The first link I posted comes from SQLAlchemy's own docs, this is from flask-sqlalchemy flask-sqlalchemy.pocoo.org/2.3/models
– Pax Vobiscum
Mar 21 at 15:55
Ok - that makes sense, thank you. I've changed them to db.Boolean, and it works in the console sending True, True, True when creating a User object. But when I do it through Edit.html, I get an typeError: '1' is not a boolean value. Have tried value=1 and value=True on the checkbox field. Seems that it's sending value=True or value=1 as a string?
– tnoe
Mar 21 at 16:24
Why did you define admin and dept_head as integers and not as booleans? docs.sqlalchemy.org/en/latest/core/…
– Pax Vobiscum
Mar 21 at 14:58
Why did you define admin and dept_head as integers and not as booleans? docs.sqlalchemy.org/en/latest/core/…
– Pax Vobiscum
Mar 21 at 14:58
Because SQLite doesn't have a boolean datatype per their v3 documentation - unless I'm reading it wrong? New to SQLite also, so that could be the issue.
– tnoe
Mar 21 at 15:47
Because SQLite doesn't have a boolean datatype per their v3 documentation - unless I'm reading it wrong? New to SQLite also, so that could be the issue.
– tnoe
Mar 21 at 15:47
You can absolutely declare it as db.Boolean, however under the hood it is still an integer. But this will tell python to deal with the field as True/False
– Pax Vobiscum
Mar 21 at 15:53
You can absolutely declare it as db.Boolean, however under the hood it is still an integer. But this will tell python to deal with the field as True/False
– Pax Vobiscum
Mar 21 at 15:53
The first link I posted comes from SQLAlchemy's own docs, this is from flask-sqlalchemy flask-sqlalchemy.pocoo.org/2.3/models
– Pax Vobiscum
Mar 21 at 15:55
The first link I posted comes from SQLAlchemy's own docs, this is from flask-sqlalchemy flask-sqlalchemy.pocoo.org/2.3/models
– Pax Vobiscum
Mar 21 at 15:55
Ok - that makes sense, thank you. I've changed them to db.Boolean, and it works in the console sending True, True, True when creating a User object. But when I do it through Edit.html, I get an typeError: '1' is not a boolean value. Have tried value=1 and value=True on the checkbox field. Seems that it's sending value=True or value=1 as a string?
– tnoe
Mar 21 at 16:24
Ok - that makes sense, thank you. I've changed them to db.Boolean, and it works in the console sending True, True, True when creating a User object. But when I do it through Edit.html, I get an typeError: '1' is not a boolean value. Have tried value=1 and value=True on the checkbox field. Seems that it's sending value=True or value=1 as a string?
– tnoe
Mar 21 at 16:24
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55282932%2fwtforms-checkbox-field-not-populating%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55282932%2fwtforms-checkbox-field-not-populating%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why did you define admin and dept_head as integers and not as booleans? docs.sqlalchemy.org/en/latest/core/…
– Pax Vobiscum
Mar 21 at 14:58
Because SQLite doesn't have a boolean datatype per their v3 documentation - unless I'm reading it wrong? New to SQLite also, so that could be the issue.
– tnoe
Mar 21 at 15:47
You can absolutely declare it as db.Boolean, however under the hood it is still an integer. But this will tell python to deal with the field as True/False
– Pax Vobiscum
Mar 21 at 15:53
The first link I posted comes from SQLAlchemy's own docs, this is from flask-sqlalchemy flask-sqlalchemy.pocoo.org/2.3/models
– Pax Vobiscum
Mar 21 at 15:55
Ok - that makes sense, thank you. I've changed them to db.Boolean, and it works in the console sending True, True, True when creating a User object. But when I do it through Edit.html, I get an typeError: '1' is not a boolean value. Have tried value=1 and value=True on the checkbox field. Seems that it's sending value=True or value=1 as a string?
– tnoe
Mar 21 at 16:24