initial commit - LeDiscord plateforme des copains
This commit is contained in:
46
backend/models/event.py
Normal file
46
backend/models/event.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text, Enum as SQLEnum, Float
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
import enum
|
||||
from config.database import Base
|
||||
|
||||
class ParticipationStatus(enum.Enum):
|
||||
PRESENT = "present"
|
||||
ABSENT = "absent"
|
||||
MAYBE = "maybe"
|
||||
PENDING = "pending"
|
||||
|
||||
class Event(Base):
|
||||
__tablename__ = "events"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String, nullable=False)
|
||||
description = Column(Text)
|
||||
location = Column(String)
|
||||
latitude = Column(Float, nullable=True) # Coordonnée latitude
|
||||
longitude = Column(Float, nullable=True) # Coordonnée longitude
|
||||
date = Column(DateTime, nullable=False)
|
||||
end_date = Column(DateTime)
|
||||
creator_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
cover_image = Column(String)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
creator = relationship("User", back_populates="created_events")
|
||||
participations = relationship("EventParticipation", back_populates="event", cascade="all, delete-orphan")
|
||||
albums = relationship("Album", back_populates="event")
|
||||
|
||||
class EventParticipation(Base):
|
||||
__tablename__ = "event_participations"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
event_id = Column(Integer, ForeignKey("events.id"), nullable=False)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
status = Column(SQLEnum(ParticipationStatus), default=ParticipationStatus.PENDING)
|
||||
response_date = Column(DateTime, default=datetime.utcnow)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
event = relationship("Event", back_populates="participations")
|
||||
user = relationship("User", back_populates="event_participations")
|
||||
Reference in New Issue
Block a user