我正在使用具有多对多关系的Flask-SQLAlchemy。而且我尝试从用户中删除当前用户,但我只收到en错误,如主题所示。我做错了我不明白。预先感谢您的帮助
我的以下型号:
subs = db.Table('subs',
db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
db.Column('request_id', db.Integer, db.ForeignKey('request.id'))
)
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(120))
role = db.Column(db.String(120))
password_hash = db.Column(db.String(120))
requests = db.relationship('Request', secondary=subs, backref=db.backref('users', lazy='dynamic'))
class Request(db.Model):
id = db.Column(db.Integer, primary_key=True)
org = db.Column(db.String(120))
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
cost = db.Column(db.Integer)
created = db.Column(db.DateTime, default= datetime.utcnow)
cost_time = db.Column(db.DateTime, default = datetime.utcnow)
我要删除的表格:
class Remove(FlaskForm):
remove = IntegerField('delete request')
submit = SubmitField('delete')
我的路线:
@app.route('/delete', methods = ['GET', 'POST'])
def delete():
form = Remove()
if form.validate_on_submit():
request = Request.query.get(form.remove.data)
request.users.remove(current_user)
db.session.commit()
return redirect('index')
return render_template('remove.html', form=form, id=id)