Add base and user models with essential fields and mixins
Created reusable `Base`, `UUIDMixin`, and `TimestampMixin` in `base.py`. Added a `User` model with attributes, relationships, and database configurations in `user.py` to establish a foundation for user-related features.
This commit is contained in:
0
backend/app/models/__init__.py
Normal file
0
backend/app/models/__init__.py
Normal file
18
backend/app/models/base.py
Normal file
18
backend/app/models/base.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# backend/models/base.py
|
||||
from datetime import datetime, timezone
|
||||
import uuid
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy import Column, DateTime, Boolean
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class TimestampMixin:
|
||||
created_at = Column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc), nullable=False)
|
||||
updated_at = Column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc),
|
||||
onupdate=lambda: datetime.now(timezone.utc), nullable=False)
|
||||
|
||||
|
||||
class UUIDMixin:
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
24
backend/app/models/user.py
Normal file
24
backend/app/models/user.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from sqlalchemy import Column, String, JSON, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
from .base import Base, TimestampMixin, UUIDMixin
|
||||
|
||||
|
||||
class User(Base, UUIDMixin, TimestampMixin):
|
||||
__tablename__ = 'users'
|
||||
|
||||
email = Column(String, unique=True, nullable=False, index=True)
|
||||
password_hash = Column(String, nullable=False)
|
||||
first_name = Column(String, nullable=False)
|
||||
last_name = Column(String, nullable=False)
|
||||
phone_number = Column(String)
|
||||
is_active = Column(Boolean, default=True, nullable=False)
|
||||
is_superuser = Column(Boolean, default=False, nullable=False)
|
||||
preferences = Column(JSON)
|
||||
|
||||
# Add relationships
|
||||
created_events = relationship("Event", back_populates="creator", foreign_keys="Event.created_by")
|
||||
managed_events = relationship("EventManager", back_populates="user")
|
||||
guest_profiles = relationship("Guest", back_populates="user")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<User {self.email}>"
|
||||
Reference in New Issue
Block a user