Add Event and EventTheme models

Introduces models for events and their themes, including fields for event details, location, timing, and settings. The `EventTheme` model supports theme customization with color palettes and fonts, while establishing relationships with the `Event` model. These additions prepare the database for event-related functionality.
This commit is contained in:
2025-02-27 18:14:47 +01:00
parent dcdfe8732c
commit ca399e5c68
2 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
# backend/models/event.py
from datetime import datetime, timezone
from sqlalchemy import (
Column, String, DateTime, Time, Boolean, Integer, ForeignKey, JSON,
UniqueConstraint
)
from sqlalchemy.orm import relationship
from sqlalchemy.dialects.postgresql import UUID
from .base import Base, TimestampMixin, UUIDMixin
class Event(Base, UUIDMixin, TimestampMixin):
__tablename__ = 'events'
# Basic Information
title = Column(String, nullable=False)
slug = Column(String, nullable=False)
description = Column(String)
# Location Details
location_name = Column(String)
location_address = Column(String)
location_url = Column(String)
# Timing - now timezone-aware
event_date = Column(DateTime(timezone=True), nullable=False)
event_start_time = Column(Time)
event_end_time = Column(Time)
timezone = Column(String, nullable=False)
rsvp_deadline = Column(DateTime(timezone=True))
# Rest of the fields remain the same...
is_public = Column(Boolean, default=False, nullable=False)
access_code = Column(String)
created_by = Column(UUID(as_uuid=True), ForeignKey('users.id'), nullable=False)
theme_id = Column(UUID(as_uuid=True), ForeignKey('event_themes.id'))
custom_theme_settings = Column(JSON)
additional_info = Column(JSON)
is_active = Column(Boolean, default=True, nullable=False)
rsvp_enabled = Column(Boolean, default=True, nullable=False)
gift_registry_enabled = Column(Boolean, default=True, nullable=False)
updates_enabled = Column(Boolean, default=True, nullable=False)
max_guests_per_invitation = Column(Integer)
contact_email = Column(String)
contact_phone = Column(String)
# Relationships remain the same...
creator = relationship("User", back_populates="created_events", foreign_keys=[created_by])
theme = relationship("EventTheme", back_populates="events")
managers = relationship("EventManager", back_populates="event")
guests = relationship("Guest", back_populates="event")
gift_items = relationship("GiftItem", back_populates="event")
media = relationship("EventMedia", back_populates="event")
updates = relationship("EventUpdate", back_populates="event")
rsvps = relationship("RSVP", back_populates="event")
__table_args__ = (
UniqueConstraint('slug', name='uq_event_slug'),
)
def __repr__(self):
return f"<Event {self.title} ({self.event_date})>"

View File

@@ -0,0 +1,19 @@
from sqlalchemy import Column, String, JSON
from sqlalchemy.orm import relationship
from .base import Base, TimestampMixin, UUIDMixin
class EventTheme(Base, UUIDMixin, TimestampMixin):
__tablename__ = 'event_themes'
name = Column(String, nullable=False)
description = Column(String)
preview_image_url = Column(String)
color_palette = Column(JSON, nullable=False)
fonts = Column(JSON, nullable=False)
# Relationship with Event
events = relationship("Event", back_populates="theme")
def __repr__(self):
return f"<EventTheme {self.name}>"