init
This commit is contained in:
17
app/models/__init__.py
Normal file
17
app/models/__init__.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from app.models.user import User
|
||||
from app.models.hackathon import Hackathon
|
||||
from app.models.hackathon_participant import HackathonParticipant
|
||||
from app.models.team import Team
|
||||
from app.models.team_member import TeamMember
|
||||
from app.models.task import Task
|
||||
from app.models.submission import Submission
|
||||
|
||||
__all__ = [
|
||||
"User",
|
||||
"Hackathon",
|
||||
"HackathonParticipant",
|
||||
"Team",
|
||||
"TeamMember",
|
||||
"Task",
|
||||
"Submission",
|
||||
]
|
||||
29
app/models/hackathon.py
Normal file
29
app/models/hackathon.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlmodel import SQLModel, Field, Relationship
|
||||
|
||||
|
||||
class Hackathon(SQLModel, table=True):
|
||||
__tablename__ = "hackathons"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
title: str = Field(max_length=200)
|
||||
description: str
|
||||
start_date: datetime
|
||||
end_date: datetime
|
||||
organizer_id: int = Field(foreign_key="users.id")
|
||||
|
||||
# Relationships
|
||||
organizer: "User" = Relationship(back_populates="organized_hackathons")
|
||||
participants: list["HackathonParticipant"] = Relationship(
|
||||
back_populates="hackathon",
|
||||
sa_relationship_kwargs={"cascade": "all, delete"},
|
||||
)
|
||||
teams: list["Team"] = Relationship(
|
||||
back_populates="hackathon",
|
||||
sa_relationship_kwargs={"cascade": "all, delete"},
|
||||
)
|
||||
tasks: list["Task"] = Relationship(
|
||||
back_populates="hackathon",
|
||||
sa_relationship_kwargs={"cascade": "all, delete"},
|
||||
)
|
||||
16
app/models/hackathon_participant.py
Normal file
16
app/models/hackathon_participant.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from sqlmodel import SQLModel, Field, Relationship
|
||||
|
||||
|
||||
class HackathonParticipant(SQLModel, table=True):
|
||||
"""Регистрация участника на хакатон (many-to-many: User <-> Hackathon)."""
|
||||
|
||||
__tablename__ = "hackathon_participants"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
user_id: int = Field(foreign_key="users.id")
|
||||
hackathon_id: int = Field(foreign_key="hackathons.id")
|
||||
is_confirmed: bool = Field(default=False)
|
||||
|
||||
# Relationships
|
||||
user: "User" = Relationship(back_populates="registrations")
|
||||
hackathon: "Hackathon" = Relationship(back_populates="participants")
|
||||
18
app/models/submission.py
Normal file
18
app/models/submission.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlmodel import SQLModel, Field, Relationship
|
||||
|
||||
|
||||
class Submission(SQLModel, table=True):
|
||||
__tablename__ = "submissions"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
team_id: int = Field(foreign_key="teams.id")
|
||||
task_id: int = Field(foreign_key="tasks.id")
|
||||
description: str
|
||||
file_url: str | None = None
|
||||
submitted_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
team: "Team" = Relationship(back_populates="submissions")
|
||||
task: "Task" = Relationship(back_populates="submissions")
|
||||
19
app/models/task.py
Normal file
19
app/models/task.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from sqlmodel import SQLModel, Field, Relationship
|
||||
|
||||
|
||||
class Task(SQLModel, table=True):
|
||||
__tablename__ = "tasks"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
hackathon_id: int = Field(foreign_key="hackathons.id")
|
||||
title: str = Field(max_length=200)
|
||||
description: str
|
||||
requirements: str
|
||||
evaluation_criteria: str
|
||||
|
||||
# Relationships
|
||||
hackathon: "Hackathon" = Relationship(back_populates="tasks")
|
||||
submissions: list["Submission"] = Relationship(
|
||||
back_populates="task",
|
||||
sa_relationship_kwargs={"cascade": "all, delete"},
|
||||
)
|
||||
20
app/models/team.py
Normal file
20
app/models/team.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from sqlmodel import SQLModel, Field, Relationship
|
||||
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
__tablename__ = "teams"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(max_length=100)
|
||||
hackathon_id: int = Field(foreign_key="hackathons.id")
|
||||
|
||||
# Relationships
|
||||
hackathon: "Hackathon" = Relationship(back_populates="teams")
|
||||
members: list["TeamMember"] = Relationship(
|
||||
back_populates="team",
|
||||
sa_relationship_kwargs={"cascade": "all, delete"},
|
||||
)
|
||||
submissions: list["Submission"] = Relationship(
|
||||
back_populates="team",
|
||||
sa_relationship_kwargs={"cascade": "all, delete"},
|
||||
)
|
||||
16
app/models/team_member.py
Normal file
16
app/models/team_member.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from sqlmodel import SQLModel, Field, Relationship
|
||||
|
||||
|
||||
class TeamMember(SQLModel, table=True):
|
||||
"""Участник команды (many-to-many: User <-> Team)."""
|
||||
|
||||
__tablename__ = "team_members"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
user_id: int = Field(foreign_key="users.id")
|
||||
team_id: int = Field(foreign_key="teams.id")
|
||||
role: str = Field(default="participant", max_length=50) # programmer, designer, marketer...
|
||||
|
||||
# Relationships
|
||||
user: "User" = Relationship(back_populates="team_memberships")
|
||||
team: "Team" = Relationship(back_populates="members")
|
||||
26
app/models/user.py
Normal file
26
app/models/user.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from sqlmodel import SQLModel, Field, Relationship
|
||||
|
||||
|
||||
class User(SQLModel, table=True):
|
||||
__tablename__ = "users"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(max_length=100)
|
||||
email: str = Field(max_length=255, unique=True, index=True)
|
||||
phone: str | None = Field(default=None, max_length=20)
|
||||
hashed_password: str
|
||||
is_organizer: bool = Field(default=False)
|
||||
|
||||
# Relationships
|
||||
organized_hackathons: list["Hackathon"] = Relationship(
|
||||
back_populates="organizer",
|
||||
sa_relationship_kwargs={"cascade": "all, delete"},
|
||||
)
|
||||
registrations: list["HackathonParticipant"] = Relationship(
|
||||
back_populates="user",
|
||||
sa_relationship_kwargs={"cascade": "all, delete"},
|
||||
)
|
||||
team_memberships: list["TeamMember"] = Relationship(
|
||||
back_populates="user",
|
||||
sa_relationship_kwargs={"cascade": "all, delete"},
|
||||
)
|
||||
Reference in New Issue
Block a user