在炼金术中连接两个表并将其显示给jinja2

c6ubokkw  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(229)

所以我想在users表和image\u比较表上进行连接。仅命名用户表。
这是我的模型

class ImageComparing(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    id_user = db.Column(db.Integer, db.ForeignKey('users.id'))
    original_image = db.Column(db.String(100))
    compressed_image = db.Column(db.String(100))
    rmse = db.Column(db.Float)
    ssim = db.Column(db.Float)
    tanggal = db.Column(db.DateTime(timezone=True))
    users = db.relationship('Users')

class Users(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    NIM = db.Column(db.String(11), unique=True)
    nama = db.Column(db.String(50))
    id_role = db.Column(db.Integer, db.ForeignKey('role.id'))
    id_kelas = db.Column(db.Integer, db.ForeignKey('kelas.id'))
    email = db.Column(db.String(50), unique=True)
    password = db.Column(db.String(256))
    image_profile = db.Column(db.String(50))
    role = db.relationship('Role')
    kelas = db.relationship('Kelas')

这是我的路线

@views.route('/history_perbandingan')
@login_required
def data_perbandingan():
    title = "Data Hasil Perbandingan Gambar"

    result = db.session.query(Users, ImageComparing).join(ImageComparing, Users.id == ImageComparing.id_user).all()

    # compare = ImageComparing.query.all()
    # users = Users.query.all()
    # result = db.session.query(users).join(compare).all()

    return render_template('data_perbandingan.html', title=title, result=result, user=current_user)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题