0

I'm learning Flask and I decided to build a simple market app. I have two types of users, sellers and buyers. I have created a user class which has two children (buyer, seller). sellers should have this ability to upload some products in order to sell them. Therefore I should create a class which is a child of seller. I think since the relation between user and buyer is on to many, the relation between the product and seller should be many to many.

If I've done something right up until now, how should I create this new table.

1

1 Answer 1

1

It would be more beneficial to create product database in a way that do not inherit from seller. and that relate the user database to product through another table, something like this:

class User(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    ...
class Product(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    ...
class Order(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
    user = db.relationship('User', backref=db.backref("order", cascade="all, delete-orphan"))
    product = db.relationship('Product', backref=db.backref("order", cascade="all, delete-orphan"))





Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.