I've got a table in my database
class Operator(db.Model):
id = db.Column(db.Integer, primary_key=True)
login = db.Column(db.String(100))
calls = db.relationship('Call', backref='operator', lazy='dynamic')
and I want to get all login
from this table. So I do
operators = db.session.query(models.Operator.login).all()
print(operators)
And I suppose to get a list of logins
but in fact I've got a list of tuples
[('ivanov',), ('petrov',)]
Of course I can manage this data but I can't understand why it's formatted in that way? Why it has empty second element in every tuple? Maybe I do something wrong and there is easier way to get list of logins
?
If you want to get a list of login
s something like this will do what you need:
operators = db.session.query(Operator).all()
operators = [op.login for op in operators]
The tuple representation is the standard.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.