0
I am trying to sort the Transaction table id accordingly:
from sqlalchemy import desc
from sqlalchemy.orm import query
from website.models import Transaction
def home():
transactions = query.order_by(Transaction.id.desc())
flash(transactions)
return render_template("home.html", user=current_user)
And also as follows:
from sqlalchemy import desc
from sqlalchemy.orm import query
from website.models import Transaction
def home():
transactions = Transaction.oder_by(Transaction.id.desc()).all()
flash(transactions)
return render_template("home.html", user=current_user)
*The table:
class Transaction(db.Model):
__tablename__ = 'transaction'
id = db.Column(db.Integer, primary_key=True)
tipo = db.Column(db.String(150))
nome_cripto = db.Column(db.String(150))
quant = db.Column(db.Float)
data = db.Column(db.String(150))
quotation = db.Column(db.Float)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
cripto = db.relationship("Cripto", back_populates="transaction", uselist=False)
But returning, in both attempts: "Attributeerror: type Object 'User' has no attribute 'oder_by'". What is the cause of this? Some import is missing?
Worse that I made a mistake, but unfortunately even correcting gave the same error.
– Ruann Yury
If you are giving the same error, then you are wrong somewhere else in the code. Look straight at the line that appears in the msg of ero
– Evilmaax