diff --git a/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/README.md b/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/README.md index 3e25e4c1..d6bcc9e0 100644 --- a/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/README.md +++ b/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/README.md @@ -24,7 +24,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") @@ -117,7 +117,7 @@ class TagsInStore(MethodView): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/end/models/tag.py b/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/end/models/tag.py index 0bab33a9..2a395c23 100644 --- a/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/end/models/tag.py +++ b/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/end/resources/tag.py b/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/end/resources/tag.py index 593d6e4a..66548593 100644 --- a/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/end/resources/tag.py +++ b/docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/end/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/README.md b/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/README.md index 4171bb03..5786ac8c 100644 --- a/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/README.md +++ b/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/README.md @@ -84,7 +84,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") @@ -190,7 +190,7 @@ class TagsInStore(MethodView): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/end/models/tag.py b/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/end/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/end/models/tag.py +++ b/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/end/resources/tag.py b/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/end/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/end/resources/tag.py +++ b/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/end/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/start/models/tag.py b/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/start/models/tag.py index 0bab33a9..2a395c23 100644 --- a/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/start/models/tag.py +++ b/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/start/resources/tag.py b/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/start/resources/tag.py index 593d6e4a..66548593 100644 --- a/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/start/resources/tag.py +++ b/docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/start/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/README.md b/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/README.md index 510ca1c4..1f56f327 100644 --- a/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/README.md +++ b/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/README.md @@ -66,5 +66,5 @@ def create_app(db_url=None): :::caution The secret key set here, `"jose"`, is **not very safe**. -Instead you should generate a long and random secret key using something like `secrets.SystemRandom().getrandbits(128)`. +Instead you should generate a long and random secret key using something like `str(secrets.SystemRandom().getrandbits(128))`. ::: diff --git a/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/end/models/tag.py b/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/end/models/tag.py index 5e92c9fa..f65023bd 100644 --- a/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/end/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/end/models/tag.py @@ -5,8 +5,9 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") - items = db.relationship("ItemModel", back_populates="tags", secondary="items_tags") + items = db.relationship( + "ItemModel", back_populates="tags", secondary="items_tags") diff --git a/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/end/resources/tag.py b/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/end/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/end/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/end/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/start/models/tag.py b/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/start/models/tag.py index 5e92c9fa..f65023bd 100644 --- a/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/start/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/start/models/tag.py @@ -5,8 +5,9 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") - items = db.relationship("ItemModel", back_populates="tags", secondary="items_tags") + items = db.relationship( + "ItemModel", back_populates="tags", secondary="items_tags") diff --git a/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/start/resources/tag.py b/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/start/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/start/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/start/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/end/models/tag.py b/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/end/models/tag.py index 5e92c9fa..f65023bd 100644 --- a/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/end/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/end/models/tag.py @@ -5,8 +5,9 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") - items = db.relationship("ItemModel", back_populates="tags", secondary="items_tags") + items = db.relationship( + "ItemModel", back_populates="tags", secondary="items_tags") diff --git a/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/end/resources/tag.py b/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/end/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/end/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/end/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/start/models/tag.py b/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/start/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/start/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/start/resources/tag.py b/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/start/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/start/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/05_user_model_and_schema/start/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/end/models/tag.py b/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/end/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/end/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/end/resources/tag.py b/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/end/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/end/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/end/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/start/models/tag.py b/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/start/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/start/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/start/resources/tag.py b/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/start/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/start/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/start/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/end/models/tag.py b/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/end/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/end/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/end/resources/tag.py b/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/end/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/end/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/end/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/start/models/tag.py b/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/start/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/start/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/start/resources/tag.py b/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/start/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/start/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/07_login_users_rest_api/start/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/end/models/tag.py b/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/end/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/end/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/end/resources/tag.py b/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/end/resources/tag.py index d42ee548..71142e50 100644 --- a/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/end/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/end/resources/tag.py @@ -20,9 +20,8 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") - tag = TagModel(**tag_data, store_id=store_id) try: diff --git a/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/start/models/tag.py b/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/start/models/tag.py index 5e92c9fa..f65023bd 100644 --- a/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/start/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/start/models/tag.py @@ -5,8 +5,9 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") - items = db.relationship("ItemModel", back_populates="tags", secondary="items_tags") + items = db.relationship( + "ItemModel", back_populates="tags", secondary="items_tags") diff --git a/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/start/resources/tag.py b/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/start/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/start/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/start/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/end/models/tag.py b/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/end/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/end/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/end/resources/tag.py b/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/end/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/end/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/end/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/start/models/tag.py b/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/start/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/start/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/start/resources/tag.py b/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/start/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/start/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/start/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/end/models/tag.py b/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/end/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/end/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/end/resources/tag.py b/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/end/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/end/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/end/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/start/models/tag.py b/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/start/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/start/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/start/resources/tag.py b/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/start/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/start/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/start/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/end/models/tag.py b/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/end/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/end/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/end/resources/tag.py b/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/end/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/end/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/end/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/start/models/tag.py b/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/start/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/start/models/tag.py +++ b/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/start/resources/tag.py b/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/start/resources/tag.py index d42ee548..b2450fe5 100644 --- a/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/start/resources/tag.py +++ b/docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/start/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/docs/docs/11_deploy_to_render/05_environment_variables_and_migrations/README.md b/docs/docs/11_deploy_to_render/05_environment_variables_and_migrations/README.md index 97703a93..b73aaf85 100644 --- a/docs/docs/11_deploy_to_render/05_environment_variables_and_migrations/README.md +++ b/docs/docs/11_deploy_to_render/05_environment_variables_and_migrations/README.md @@ -135,7 +135,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) # highlight-start store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) # highlight-end diff --git a/docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/end/models/tag.py b/docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/end/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/end/models/tag.py +++ b/docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/start/models/tag.py b/docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/start/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/start/models/tag.py +++ b/docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/12_task_queues_emails/02_send_email_user_registration/end/models/tag.py b/docs/docs/12_task_queues_emails/02_send_email_user_registration/end/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/02_send_email_user_registration/end/models/tag.py +++ b/docs/docs/12_task_queues_emails/02_send_email_user_registration/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/12_task_queues_emails/02_send_email_user_registration/start/models/tag.py b/docs/docs/12_task_queues_emails/02_send_email_user_registration/start/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/02_send_email_user_registration/start/models/tag.py +++ b/docs/docs/12_task_queues_emails/02_send_email_user_registration/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/12_task_queues_emails/04_populate_rq_task_queue/end/models/tag.py b/docs/docs/12_task_queues_emails/04_populate_rq_task_queue/end/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/04_populate_rq_task_queue/end/models/tag.py +++ b/docs/docs/12_task_queues_emails/04_populate_rq_task_queue/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/12_task_queues_emails/04_populate_rq_task_queue/start/models/tag.py b/docs/docs/12_task_queues_emails/04_populate_rq_task_queue/start/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/04_populate_rq_task_queue/start/models/tag.py +++ b/docs/docs/12_task_queues_emails/04_populate_rq_task_queue/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/12_task_queues_emails/05_rq_background_worker/end/models/tag.py b/docs/docs/12_task_queues_emails/05_rq_background_worker/end/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/05_rq_background_worker/end/models/tag.py +++ b/docs/docs/12_task_queues_emails/05_rq_background_worker/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/12_task_queues_emails/05_rq_background_worker/start/models/tag.py b/docs/docs/12_task_queues_emails/05_rq_background_worker/start/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/05_rq_background_worker/start/models/tag.py +++ b/docs/docs/12_task_queues_emails/05_rq_background_worker/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/12_task_queues_emails/06_sending_html_emails/end/models/tag.py b/docs/docs/12_task_queues_emails/06_sending_html_emails/end/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/06_sending_html_emails/end/models/tag.py +++ b/docs/docs/12_task_queues_emails/06_sending_html_emails/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/12_task_queues_emails/06_sending_html_emails/start/models/tag.py b/docs/docs/12_task_queues_emails/06_sending_html_emails/start/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/06_sending_html_emails/start/models/tag.py +++ b/docs/docs/12_task_queues_emails/06_sending_html_emails/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/12_task_queues_emails/07_deploy_background_worker_render/end/models/tag.py b/docs/docs/12_task_queues_emails/07_deploy_background_worker_render/end/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/07_deploy_background_worker_render/end/models/tag.py +++ b/docs/docs/12_task_queues_emails/07_deploy_background_worker_render/end/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/docs/docs/12_task_queues_emails/07_deploy_background_worker_render/start/models/tag.py b/docs/docs/12_task_queues_emails/07_deploy_background_worker_render/start/models/tag.py index 008e8d37..37b8ed85 100644 --- a/docs/docs/12_task_queues_emails/07_deploy_background_worker_render/start/models/tag.py +++ b/docs/docs/12_task_queues_emails/07_deploy_background_worker_render/start/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer, db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/project/05-add-many-to-many/models/tag.py b/project/05-add-many-to-many/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/project/05-add-many-to-many/models/tag.py +++ b/project/05-add-many-to-many/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/project/05-add-many-to-many/resources/tag.py b/project/05-add-many-to-many/resources/tag.py index d42ee548..b2450fe5 100644 --- a/project/05-add-many-to-many/resources/tag.py +++ b/project/05-add-many-to-many/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/project/06-add-db-migrations/models/tag.py b/project/06-add-db-migrations/models/tag.py index 5e92c9fa..32103cb1 100644 --- a/project/06-add-db-migrations/models/tag.py +++ b/project/06-add-db-migrations/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False) store = db.relationship("StoreModel", back_populates="tags") diff --git a/project/06-add-db-migrations/resources/tag.py b/project/06-add-db-migrations/resources/tag.py index d42ee548..b2450fe5 100644 --- a/project/06-add-db-migrations/resources/tag.py +++ b/project/06-add-db-migrations/resources/tag.py @@ -20,7 +20,7 @@ def get(self, store_id): @blp.arguments(TagSchema) @blp.response(201, TagSchema) def post(self, tag_data, store_id): - if TagModel.query.filter(TagModel.store_id == store_id).first(): + if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first(): abort(400, message="A tag with that name already exists in that store.") tag = TagModel(**tag_data, store_id=store_id) diff --git a/project/using-flask-restful/models/tag.py b/project/using-flask-restful/models/tag.py index 23332527..6f5a1bcf 100644 --- a/project/using-flask-restful/models/tag.py +++ b/project/using-flask-restful/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) items = db.relationship("ItemModel", back_populates="tags", secondary="items_tags") def json(self): diff --git a/project/using-flask-restx/models/tag.py b/project/using-flask-restx/models/tag.py index 23332527..6f5a1bcf 100644 --- a/project/using-flask-restx/models/tag.py +++ b/project/using-flask-restx/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) items = db.relationship("ItemModel", back_populates="tags", secondary="items_tags") def json(self): diff --git a/project/using-flask-smorest/models/tag.py b/project/using-flask-smorest/models/tag.py index 23332527..6f5a1bcf 100644 --- a/project/using-flask-smorest/models/tag.py +++ b/project/using-flask-smorest/models/tag.py @@ -5,7 +5,7 @@ class TagModel(db.Model): __tablename__ = "tags" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(80), unique=True, nullable=False) + name = db.Column(db.String(80), unique=False, nullable=False) items = db.relationship("ItemModel", back_populates="tags", secondary="items_tags") def json(self):