All checks were successful
Build and Push Docker Image / build (push) Successful in 28s
37 lines
951 B
Python
37 lines
951 B
Python
"""
|
|
Database schemas.
|
|
"""
|
|
|
|
from tortoise import Tortoise, fields
|
|
from tortoise.models import Model
|
|
|
|
|
|
class Player(Model):
|
|
username = fields.CharField(max_length=20)
|
|
steam_id = fields.CharField(max_length=20)
|
|
last_connection = fields.DatetimeField()
|
|
last_disconnection = fields.DatetimeField()
|
|
deaths = fields.ManyToManyField(
|
|
model_name="models.PlayerDeath",
|
|
on_delete=fields.CASCADE
|
|
)
|
|
|
|
@property
|
|
def is_online(self):
|
|
if not self.last_connection:
|
|
return False
|
|
|
|
return (self.last_connection and not self.last_disconnection) \
|
|
or self.last_connection > self.last_disconnection
|
|
|
|
|
|
class PlayerDeath(Model):
|
|
coordinate_x = fields.IntField()
|
|
coordinate_y = fields.IntField()
|
|
coordinate_z = fields.IntField()
|
|
cause = fields.CharField(max_length=32)
|
|
timestamp = fields.DatetimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
table = "player_deaths"
|