Skip to content

Commit

Permalink
validations
Browse files Browse the repository at this point in the history
  • Loading branch information
statsumi97 committed Jan 22, 2024
1 parent 01bb2b9 commit dd22c46
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions server/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from sqlalchemy_serializer import SerializerMixin
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm import validates

from config import db

Expand All @@ -14,6 +15,28 @@ class Users(db.Model,SerializerMixin):
#__RELATIONSHIPS
swipes = db.relationship("Swipes", back_populates="user")

#_SERIALIZATION
serialize_rules = ('-swipes.user', )

#_VALIDATIONS
@validates('username')
def validate_username(self, key, value):
if 0 < len(value) <= 25:
return value
else:
raise ValueError

@validates('passwordhash')
def validate_passwordhash(self, key, value):
if 0 < len(value) <= 25:
return value
else:
raise ValueError

#validation for @ (valid email) in user_email

def __repr__(self):
return f'<Users {self.id}, {self.username}>'

class Recipes(db.Model,SerializerMixin):
__tablename__ = "recipe"
Expand All @@ -26,6 +49,14 @@ class Recipes(db.Model,SerializerMixin):
#__RELATIONSHIPS
swipes = db.relationship("Swipes", back_populates="recipe")

#_SERIALIZATION
serialize_rules = ('-swipes.recipe', )

#_VALIDATIONS

def __repr__(self):
return f'<Recipes {self.id}, {self.name}>'

class Swipes(db.Model, SerializerMixin):
__tablename__ = "swipes"

Expand All @@ -39,3 +70,11 @@ class Swipes(db.Model, SerializerMixin):
#__RELATIONSHIPS
user = db.relationship("Users", back_populates = "swipes")
recipe = db.relationship("Recipes", back_populates = "swipes")

#_SERIALIZATIONS
serialize_rules = ('-user.swipes', '-recipe.swipes')

#_VALIDATIONS

def __repr__(self):
return f'<Swipes {self.id}, {self.swipe}, {self.user_id}, {self.recipe_id}>'

0 comments on commit dd22c46

Please sign in to comment.