```
Rename metadata fields for clarity and fix imports. Updated metadata-related field names across models to improve clarity and consistency (e.g., `metadata` to `media_metadata` and `notification_metadata`). Fixed an error in `guest_gifts` metadata reference and added a proper imports initialization in `__init__.py` for all models. ```
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
"""
|
||||||
|
Models package initialization.
|
||||||
|
Imports all models to ensure they're registered with SQLAlchemy.
|
||||||
|
"""
|
||||||
|
from .base import Base, TimestampMixin, UUIDMixin
|
||||||
|
|
||||||
|
# Import user model
|
||||||
|
from .user import User
|
||||||
|
|
||||||
|
# Import event-related models
|
||||||
|
from .event import Event
|
||||||
|
from .event_manager import EventManager, EventManagerRole, init_event_owner
|
||||||
|
from .event_theme import EventTheme
|
||||||
|
from .event_media import EventMedia, MediaType, MediaPurpose
|
||||||
|
|
||||||
|
# Import guest and RSVP models
|
||||||
|
from .guest import Guest, GuestStatus, guest_gifts
|
||||||
|
from .rsvp import RSVP, RSVPStatus
|
||||||
|
|
||||||
|
# Import gift-related models
|
||||||
|
from .gift import (
|
||||||
|
GiftItem, GiftStatus, GiftPriority, GiftCategory,
|
||||||
|
GiftPurchase
|
||||||
|
)
|
||||||
|
|
||||||
|
# Import new models
|
||||||
|
from .email_template import EmailTemplate, TemplateType
|
||||||
|
from .notification_log import NotificationLog, NotificationType, NotificationStatus
|
||||||
|
from .activity_log import ActivityLog, ActivityType
|
||||||
|
|
||||||
|
# Make sure all models are imported above this line
|
||||||
|
__all__ = [
|
||||||
|
'Base', 'TimestampMixin', 'UUIDMixin',
|
||||||
|
'User',
|
||||||
|
'Event', 'EventManager', 'EventManagerRole', 'EventTheme', 'EventMedia',
|
||||||
|
'Guest', 'GuestStatus', 'RSVP', 'RSVPStatus',
|
||||||
|
'GiftItem', 'GiftStatus', 'GiftPriority', 'GiftCategory', 'GiftPurchase',
|
||||||
|
'EmailTemplate', 'TemplateType',
|
||||||
|
'NotificationLog', 'NotificationType', 'NotificationStatus',
|
||||||
|
'ActivityLog', 'ActivityType',
|
||||||
|
]
|
||||||
@@ -59,21 +59,21 @@ class ActivityLog(Base, UUIDMixin, TimestampMixin):
|
|||||||
# Request Information
|
# Request Information
|
||||||
ip_address = Column(String)
|
ip_address = Column(String)
|
||||||
user_agent = Column(String)
|
user_agent = Column(String)
|
||||||
|
|
||||||
# Additional Data
|
# Additional Data
|
||||||
data = Column(JSONB, default=dict)
|
activity_data = Column(JSONB, default=dict)
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
event = relationship("Event")
|
event = relationship("Event")
|
||||||
user = relationship("User", foreign_keys=[user_id])
|
user = relationship("User", foreign_keys=[user_id])
|
||||||
guest = relationship("Guest")
|
guest = relationship("Guest")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<ActivityLog {self.activity_type.value} event_id={self.event_id}>"
|
return f"<ActivityLog {self.activity_type.value} event_id={self.event_id}>"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def log_event_activity(cls, activity_type, event_id, user_id=None, description=None,
|
def log_event_activity(cls, activity_type, event_id, user_id=None, description=None,
|
||||||
ip_address=None, user_agent=None, **data):
|
ip_address=None, user_agent=None, **data):
|
||||||
"""
|
"""
|
||||||
Helper method to create an event activity log entry
|
Helper method to create an event activity log entry
|
||||||
"""
|
"""
|
||||||
@@ -84,12 +84,12 @@ class ActivityLog(Base, UUIDMixin, TimestampMixin):
|
|||||||
description=description,
|
description=description,
|
||||||
ip_address=ip_address,
|
ip_address=ip_address,
|
||||||
user_agent=user_agent,
|
user_agent=user_agent,
|
||||||
data=data
|
activity_data=data
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def log_user_activity(cls, activity_type, user_id, event_id=None, description=None,
|
def log_user_activity(cls, activity_type, user_id, event_id=None, description=None,
|
||||||
ip_address=None, user_agent=None, **data):
|
ip_address=None, user_agent=None, **data):
|
||||||
"""
|
"""
|
||||||
Helper method to create a user activity log entry
|
Helper method to create a user activity log entry
|
||||||
"""
|
"""
|
||||||
@@ -100,12 +100,12 @@ class ActivityLog(Base, UUIDMixin, TimestampMixin):
|
|||||||
description=description,
|
description=description,
|
||||||
ip_address=ip_address,
|
ip_address=ip_address,
|
||||||
user_agent=user_agent,
|
user_agent=user_agent,
|
||||||
data=data
|
activity_data=data
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def log_guest_activity(cls, activity_type, guest_id, event_id, description=None,
|
def log_guest_activity(cls, activity_type, guest_id, event_id, description=None,
|
||||||
ip_address=None, user_agent=None, **data):
|
ip_address=None, user_agent=None, **data):
|
||||||
"""
|
"""
|
||||||
Helper method to create a guest activity log entry
|
Helper method to create a guest activity log entry
|
||||||
"""
|
"""
|
||||||
@@ -116,5 +116,5 @@ class ActivityLog(Base, UUIDMixin, TimestampMixin):
|
|||||||
description=description,
|
description=description,
|
||||||
ip_address=ip_address,
|
ip_address=ip_address,
|
||||||
user_agent=user_agent,
|
user_agent=user_agent,
|
||||||
data=data
|
activity_data=data
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class EventMedia(Base, UUIDMixin, TimestampMixin):
|
|||||||
description = Column(String)
|
description = Column(String)
|
||||||
|
|
||||||
# Additional Metadata
|
# Additional Metadata
|
||||||
metadata = Column(JSON, default=dict)
|
media_metadata = Column(JSON, default=dict)
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
event = relationship("Event", back_populates="media")
|
event = relationship("Event", back_populates="media")
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class Guest(Base, UUIDMixin, TimestampMixin):
|
|||||||
# Association table for guest gifts (many-to-many relationship)
|
# Association table for guest gifts (many-to-many relationship)
|
||||||
guest_gifts = Table(
|
guest_gifts = Table(
|
||||||
'guest_gifts',
|
'guest_gifts',
|
||||||
Base.metadata,
|
Base.notification_metadata,
|
||||||
Column('guest_id', UUID(as_uuid=True), ForeignKey('guests.id'), primary_key=True),
|
Column('guest_id', UUID(as_uuid=True), ForeignKey('guests.id'), primary_key=True),
|
||||||
Column('gift_id', UUID(as_uuid=True), ForeignKey('gift_items.id'), primary_key=True),
|
Column('gift_id', UUID(as_uuid=True), ForeignKey('gift_items.id'), primary_key=True),
|
||||||
Column('reserved_at', DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)),
|
Column('reserved_at', DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from sqlalchemy import Column, String, ForeignKey, Enum as SQLEnum, Text, DateTime
|
from sqlalchemy import Column, String, ForeignKey, Enum as SQLEnum, Text, DateTime, Integer
|
||||||
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ class NotificationLog(Base, UUIDMixin, TimestampMixin):
|
|||||||
external_id = Column(String) # ID from external provider (SendGrid, Twilio, etc.)
|
external_id = Column(String) # ID from external provider (SendGrid, Twilio, etc.)
|
||||||
|
|
||||||
# Additional Data
|
# Additional Data
|
||||||
metadata = Column(JSONB, default=dict)
|
notification_metadata = Column(JSONB, default=dict)
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
event = relationship("Event")
|
event = relationship("Event")
|
||||||
|
|||||||
Reference in New Issue
Block a user