From c7ab772afb140e6a8a5a86aeb4ccf02bb6551b66 Mon Sep 17 00:00:00 2001 From: someone624 Date: Fri, 22 Nov 2024 13:43:46 +0100 Subject: [PATCH] Create user_model.py --- src/models/user_model.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/models/user_model.py diff --git a/src/models/user_model.py b/src/models/user_model.py new file mode 100644 index 0000000..4cd6130 --- /dev/null +++ b/src/models/user_model.py @@ -0,0 +1,28 @@ +from sqlalchemy import Column, Integer, String, DateTime +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import validates +import datetime + +Base = declarative_base() + +class User(Base): + __tablename__ = 'users' + + id = Column(Integer, primary_key=True, autoincrement=True) + username = Column(String(100), unique=True, nullable=False) + email = Column(String(100), unique=True, nullable=False) + password_hash = Column(String(255), nullable=False) + created_at = Column(DateTime, default=datetime.datetime.utcnow) + + @validates('email') + def validate_email(self, key, email): + # Ensure the email is lowercased + return email.lower() + + def __repr__(self): + return f"" + + def __init__(self, username, email, password_hash): + self.username = username + self.email = email + self.password_hash = password_hash