-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
32 lines (26 loc) · 1.16 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from sqlalchemy import Column, Integer, String, Float, ForeignKey, Boolean, BigInteger
from sqlalchemy.orm import relationship
from db import Base
class User(Base):
__tablename__ = "users"
id = Column(BigInteger, primary_key=True, index=True)
name = Column(String, index=True)
balance = Column(Float, default=0.0)
class Event(Base):
__tablename__ = "events"
id = Column(Integer, primary_key=True, index=True)
title = Column(String, index=True)
option_1 = Column(String) # 選択肢1
option_2 = Column(String) # 選択肢2
winning_option = Column(String, nullable=True) # 勝った方の選択肢
available = Column(Boolean, default=True) # イベントが有効かどうか
bets = relationship("Bet", back_populates="event")
class Bet(Base):
__tablename__ = "bets"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(BigInteger, ForeignKey("users.id"))
event_id = Column(Integer, ForeignKey("events.id"))
option = Column(String) # ユーザーが賭けた選択肢
amount = Column(Float) # 賭け金額
event = relationship("Event", back_populates="bets")
user = relationship("User")