Problem
The following database models:
Menu Table:
class Menu(db.Model):
__tablename__ = "menu"
id = db.Column(db.Integer(), primary_key=True)
title = db.Column(db.String())
price = db.Column(db.Integer())
vegetarian = db.Column(db.Boolean())
order = db.relationship("Order", backref="menu", lazy="dynamic")
User Table:
class User(db.Model):
__tablename__="users"
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(), nullable=False, unique=True)
password = db.Column(db.String(), nullable=False)
first_name = db.Column(db.String(), nullable=False)
last_name = db.Column(db.String(), nullable=False)
admin = db.Column(db.Boolean(), default=False)
order = db.relationship("Order", backref="users")
Order Table
class Order(db.Model):
__tablename__ = "user_order"
id = db.Column(db.Integer, primary_key=True)
date_time = db.Column(db.DateTime(timezone=True), nullable=False, server_default=func.now())
menu_id = db.Column(db.Integer, db.ForeignKey("menu.id"), nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False)
The problem resides in the Order table where a user will purchase an/multiple item/s and thus be recorded as a transaction in the order table. The problem is how will I record multiple item being purchase in a single transaction with out the order Id incrementing.
E.G
Order Id | User Id | Menu Id| History
1. 1. 1. 11/11/11
1. 1. 2. 11/11/11
2. 1. 5. 14/11/11
Overall I want the user to have the ability to view their transaction history.
Is there a way to do this? Is there a simpler way?
@order.route("/" methods=["POST"])
def order_menu():
#Something
How will I go about doing a post request ordering more then 1 item?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…