Add EventMedia and GiftCategory models
Introduce EventMedia for managing media files linked to events, including file metadata, purpose, and relationships. Add GiftCategory to categorize gifts, featuring unique constraints, display options, and utility methods for handling related gifts.
This commit is contained in:
@@ -118,4 +118,62 @@ class GiftPurchase(Base, UUIDMixin):
|
||||
guest = relationship("Guest")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<GiftPurchase gift_id={self.gift_id} guest_id={self.guest_id}>"
|
||||
return f"<GiftPurchase gift_id={self.gift_id} guest_id={self.guest_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)
|
||||
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")
|
||||
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}>"
|
||||
|
||||
@property
|
||||
def total_gifts(self) -> int:
|
||||
"""Get total number of gifts in category"""
|
||||
return len(self.gifts)
|
||||
|
||||
@property
|
||||
def available_gifts(self) -> int:
|
||||
"""Get number of available gifts in category"""
|
||||
return sum(1 for gift in self.gifts
|
||||
if gift.status == 'available' and gift.is_visible)
|
||||
|
||||
def reorder_gifts(self, gift_ids: list[UUID]) -> None:
|
||||
"""
|
||||
Reorder gifts within the category
|
||||
Args:
|
||||
gift_ids: List of gift IDs in desired order
|
||||
"""
|
||||
gift_order = {gift_id: idx for idx, gift_id in enumerate(gift_ids)}
|
||||
for gift in self.gifts:
|
||||
if gift.id in gift_order:
|
||||
gift.display_order = gift_order[gift.id]
|
||||
|
||||
Reference in New Issue
Block a user