Esempio n. 1
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), nullable=False)
    userName = db.Column(db.String(20), nullable=False, unique=True)

    collections = db.relationship("Collection",
                                  cascade="all,delete",
                                  back_populates="user")
Esempio n. 2
0
class Collection(db.Model):
    __table_args__ = (db.UniqueConstraint("name",
                                          "userId",
                                          name="_user_title_uc"), )

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(40), nullable=False)
    description = db.Column(db.String(100))
    userId = db.Column(db.Integer,
                       db.ForeignKey("user.id", ondelete="CASCADE"),
                       nullable=False)

    recipes = db.relationship("Recipe",
                              secondary=RecipeCollection,
                              back_populates="collections")
    user = db.relationship("User", back_populates="collections")
Esempio n. 3
0
class Recipe(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(30), nullable=False)
    description = db.Column(db.String(200), nullable=False)
    ingredients = db.Column(db.String(200), nullable=False)
    rating = db.Column(db.Float, nullable=True)
    ethnicityId = db.Column(db.Integer,
                            db.ForeignKey("ethnicity.id"),
                            nullable=False)
    categoryId = db.Column(db.Integer,
                           db.ForeignKey("category.id"),
                           nullable=False)

    collections = db.relationship("Collection",
                                  secondary=RecipeCollection,
                                  back_populates="recipes")
    ethnicity = db.relationship("Ethnicity", back_populates="recipes")
    category = db.relationship("Category", back_populates="recipes")
Esempio n. 4
0
class Ethnicity(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(40), nullable=False, unique=True)
    description = db.Column(db.String(100))

    recipes = db.relationship("Recipe", back_populates="ethnicity")