I'm using Flask-SQLAlchemy and flask on server side. I want to create a
relationship between User(Parent), Category(Child) and item(Subchild). I
don't know if a parent-child-subchild is right way to approach this but my
end goal is to easily fetch all the items rated by user in each category.
Following is one of the cases i tried but it doesn't work, probably because
i'm doing something wrong.
I have an item table with item category(such as fiction, non-fiction, crime
book). each category have 5 items(books). I want to let user rate five
items from each category. So, i have following table.
class User(db.Model, UserMixin):
__tablename__ = "users"
id = db.Column('user_id',db.Integer, primary_key=True)
active = db.Column(db.Boolean(), nullable=False, default=False)
username = db.Column(db.String(50), nullable=False, unique=True)
password = db.Column(db.String(255), nullable=False, default='')
# do we need unique=True in any column
#let's create class for item(child) and category(parent)
class Rated_item(db.Model):
__tablename__ = 'item'
id = db.Column(db.Integer, primary_key=True)
item_id = db.Column(db.Integer)
category_id = db.Column(db.Integer)
quality = db.Column(db.String(50))
taste = db.Column(db.String(50))
user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'))
# evaluation_status is set to True, once a user finishes an item.
evaluation_status = db.Column(db.Boolean, unique=False, default=False)
Any suggestion how should i improve my table or query to get all categories
(with all the items in each category) rated by user.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.