Big refactor of gift categories model
This commit is contained in:
@@ -49,7 +49,7 @@ class Event(Base, UUIDMixin, TimestampMixin):
|
||||
managers = relationship("EventManager", back_populates="event")
|
||||
guests = relationship("Guest", back_populates="event")
|
||||
gifts = relationship("GiftItem", back_populates="event")
|
||||
gift_categories = relationship("GiftCategory", back_populates="event")
|
||||
category_associations = relationship("EventGiftCategory", back_populates="event")
|
||||
media = relationship("EventMedia", back_populates="event")
|
||||
# updates = relationship("EventUpdate", back_populates="event") # Keep commented out
|
||||
rsvps = relationship("RSVP", back_populates="event")
|
||||
|
||||
@@ -121,38 +121,47 @@ class GiftPurchase(Base, UUIDMixin):
|
||||
return f"<GiftPurchase gift_id={self.gift_id} guest_id={self.guest_id}>"
|
||||
|
||||
|
||||
class EventGiftCategory(Base):
|
||||
__tablename__ = 'event_gift_categories'
|
||||
|
||||
event_id = Column(UUID(as_uuid=True), ForeignKey('events.id'), primary_key=True)
|
||||
category_id = Column(UUID(as_uuid=True), ForeignKey('gift_categories.id'), primary_key=True)
|
||||
display_order = Column(Integer, default=0)
|
||||
is_visible = Column(Boolean, default=True)
|
||||
created_at = Column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc), nullable=False)
|
||||
|
||||
# Relationships
|
||||
event = relationship("Event", back_populates="category_associations")
|
||||
category = relationship("GiftCategory", back_populates="event_associations")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<EventGiftCategory event_id={self.event_id} category_id={self.category_id}>"
|
||||
|
||||
|
||||
class GiftCategory(Base, UUIDMixin, TimestampMixin):
|
||||
__tablename__ = 'gift_categories'
|
||||
|
||||
# Foreign Keys
|
||||
event_id = Column(UUID(as_uuid=True), ForeignKey('events.id'), nullable=False)
|
||||
created_by = Column(UUID(as_uuid=True), ForeignKey('users.id'), nullable=False)
|
||||
|
||||
# Category Details
|
||||
name = Column(String, nullable=False)
|
||||
name = Column(String, nullable=False, unique=True)
|
||||
description = Column(String)
|
||||
|
||||
# Display
|
||||
icon = Column(String) # Icon identifier or URL
|
||||
color = Column(String) # Color code (hex/rgb)
|
||||
display_order = Column(Integer, default=0)
|
||||
is_visible = Column(Boolean, default=True)
|
||||
|
||||
# Additional Settings
|
||||
custom_fields = Column(JSONB)
|
||||
|
||||
# Relationships
|
||||
event = relationship("Event", back_populates="gift_categories")
|
||||
event_associations = relationship("EventGiftCategory", back_populates="category")
|
||||
gifts = relationship("GiftItem",
|
||||
back_populates="category",
|
||||
order_by="GiftItem.display_order")
|
||||
created_by_user = relationship("User", foreign_keys=[created_by])
|
||||
|
||||
# Ensure unique category names within an event
|
||||
__table_args__ = (
|
||||
UniqueConstraint('event_id', 'name', name='uq_event_category_name'),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<GiftCategory {self.name}>"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user