Skip to content

Commit fe5f25b

Browse files
authored
Merge pull request #109 from Justin-f-Reeves/patch-tag-routes
2 parents 25684cb + 9674a8f commit fe5f25b

File tree

60 files changed

+70
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+70
-67
lines changed

docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TagModel(db.Model):
2424
__tablename__ = "tags"
2525

2626
id = db.Column(db.Integer, primary_key=True)
27-
name = db.Column(db.String(80), unique=True, nullable=False)
27+
name = db.Column(db.String(80), unique=False, nullable=False)
2828
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
2929

3030
store = db.relationship("StoreModel", back_populates="tags")
@@ -117,7 +117,7 @@ class TagsInStore(MethodView):
117117
@blp.arguments(TagSchema)
118118
@blp.response(201, TagSchema)
119119
def post(self, tag_data, store_id):
120-
if TagModel.query.filter(TagModel.store_id == store_id).first():
120+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
121121
abort(400, message="A tag with that name already exists in that store.")
122122

123123
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/end/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class TagModel(db.Model):
8484
__tablename__ = "tags"
8585

8686
id = db.Column(db.Integer, primary_key=True)
87-
name = db.Column(db.String(80), unique=True, nullable=False)
87+
name = db.Column(db.String(80), unique=False, nullable=False)
8888
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
8989

9090
store = db.relationship("StoreModel", back_populates="tags")
@@ -190,7 +190,7 @@ class TagsInStore(MethodView):
190190
@blp.arguments(TagSchema)
191191
@blp.response(201, TagSchema)
192192
def post(self, tag_data, store_id):
193-
if TagModel.query.filter(TagModel.store_id == store_id).first():
193+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
194194
abort(400, message="A tag with that name already exists in that store.")
195195

196196
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/end/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/start/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/end/models/tag.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")
12-
items = db.relationship("ItemModel", back_populates="tags", secondary="items_tags")
12+
items = db.relationship(
13+
"ItemModel", back_populates="tags", secondary="items_tags")

docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/start/models/tag.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")
12-
items = db.relationship("ItemModel", back_populates="tags", secondary="items_tags")
12+
items = db.relationship(
13+
"ItemModel", back_populates="tags", secondary="items_tags")

docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/05_user_model_and_schema/end/models/tag.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")
12-
items = db.relationship("ItemModel", back_populates="tags", secondary="items_tags")
12+
items = db.relationship(
13+
"ItemModel", back_populates="tags", secondary="items_tags")

docs/docs/08_flask_jwt_extended/05_user_model_and_schema/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/05_user_model_and_schema/start/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/05_user_model_and_schema/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/end/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/start/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/07_login_users_rest_api/end/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/07_login_users_rest_api/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/07_login_users_rest_api/start/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/07_login_users_rest_api/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/end/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/end/resources/tag.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
25-
2625
tag = TagModel(**tag_data, store_id=store_id)
2726

2827
try:

docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/start/models/tag.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")
12-
items = db.relationship("ItemModel", back_populates="tags", secondary="items_tags")
12+
items = db.relationship(
13+
"ItemModel", back_populates="tags", secondary="items_tags")

docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/end/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/start/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/end/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/start/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/end/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/start/models/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TagModel(db.Model):
55
__tablename__ = "tags"
66

77
id = db.Column(db.Integer, primary_key=True)
8-
name = db.Column(db.String(80), unique=True, nullable=False)
8+
name = db.Column(db.String(80), unique=False, nullable=False)
99
store_id = db.Column(db.Integer(), db.ForeignKey("stores.id"), nullable=False)
1010

1111
store = db.relationship("StoreModel", back_populates="tags")

docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

0 commit comments

Comments
 (0)