Skip to content

Commit

Permalink
Create user_model.py
Browse files Browse the repository at this point in the history
  • Loading branch information
someone624 authored Nov 22, 2024
1 parent e9e5ecd commit c7ab772
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/models/user_model.py
Original file line number Diff line number Diff line change
@@ -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"<User(id={self.id}, username={self.username}, email={self.email})>"

def __init__(self, username, email, password_hash):
self.username = username
self.email = email
self.password_hash = password_hash

0 comments on commit c7ab772

Please sign in to comment.