0

So what I basically want to do is have a user fill out a form and have a boolean value set to True which tells me their a user. I set it to True when I send the POST request to the database, but when I go look at the column it says "[null]". I don't understand what I'm doing wrong....

class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(120))
    last_name = db.Column(db.String(120))
    email = db.Column(db.String(180), unique=True)
    password = db.Column(db.String(255))
    isUser = db.Column(db.Boolean())
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role', secondary=roles_users,backref=db.backref('users', lazy='dynamic'))

@app.route('/post_user', methods=['POST'])
def post_user():
    user = User(request.form['first_name'], request.form['last_name'], request.form['email'], request.form['password'])
    user.isUser = True
    db.session.add(user)
    db.session.commit()
    return redirect(url_for('login'))
humbleCoder
  • 463
  • 1
  • 5
  • 18
  • 1
    try with isUser = db.Column(db.Boolean(), default=False)) and after you add the user, then change it to user.isUser = True – smundlay Nov 07 '17 at 05:15
  • @smundlay So the default worked! Thank you! How would I change it after though? – humbleCoder Nov 07 '17 at 05:22
  • I just meant after you create the user with user = User(...) you can then access user.isUser = True. Idk what the rest of the code is like but if you're doing email verification then that's where I would change the boolean from the default false to true. – smundlay Nov 07 '17 at 07:41
  • db.Boolean instead of db.Boolean(). Moreover you should validate your data before using it to instanciate. Have a look on [marshmallow](http://marshmallow.readthedocs.io/en/latest/). P.S: Please use lowercase for attribute to respect pep8 naming convetion. – Pyglouthon Nov 22 '17 at 13:46

0 Answers0