This repository has been archived on 2025-02-16. You can view files and clone it, but cannot push or open issues or pull requests.
Spiffo/utils/models.py
Corban-Lee Jones 2b6f68de0d
All checks were successful
Build and Push Docker Image / build (push) Successful in 28s
database, data folder path & file reader class
2024-12-07 23:23:10 +00:00

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"