'How to access enum field in Postgres wih python sqlalchemy
I have orders table that stores enum field named "status". I can't read it with sql alchemy.
Order table
class Order(db.Model):
__tablename__ = 'orders'
order_id = db.Column(db.Integer, primary_key=True)
order_date = db.Column(db.DateTime, default=datetime.utcnow)
status = db.Column(db.Enum(STATUS), default=STATUS.PREPARING)
total_price = db.Column(db.Integer)
user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'), index=True)
res_id = db.Column(db.Integer, db.ForeignKey('restaurants.res_id'), index=True)
Enum Class
class STATUS(enum.Enum):
PREPARING = 0
ON_THE_WAY = 1
DELIVERED = 2
CANCELLED = 3
How can i reach status field with sqlalchemy?
I'm gettin "TypeError: Object of type STATUS is not JSON serializable" error
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
