Add API Django app

master
John Montagu, the 4th Earl of Sandvich 2024-10-24 08:17:51 -07:00
parent 241e8087d4
commit eb95ff3dcb
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
13 changed files with 311 additions and 1 deletions

View File

View File

@ -0,0 +1,11 @@
from django.contrib import admin
from api.models import *
# Register your models here.
admin.site.register(Team)
admin.site.register(Player)
admin.site.register(PlayerInfo)
admin.site.register(PlayerInfo_Team)
admin.site.register(PlayerRole)

View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api'

View File

@ -0,0 +1,70 @@
# Generated by Django 5.1.2 on 2024-10-24 01:56
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Player',
fields=[
('steam_id', models.BigIntegerField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=63)),
],
),
migrations.CreateModel(
name='PlayerInfo_Team',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('team_role', models.CharField(choices=[('PL', 'Player'), ('CM', 'Coach/Mentor'), ('TC', 'Team Captain')], default='PL', max_length=2)),
('created_at', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='Team',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('team_name', models.CharField(max_length=63)),
],
),
migrations.CreateModel(
name='PlayerInfo',
fields=[
('player', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='api.player')),
],
),
migrations.CreateModel(
name='PlayerRole',
fields=[
('playerinfo_team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='api.playerinfo_team')),
('player_role', models.CharField(choices=[('P_SCOUT', 'Pocket Scout'), ('F_SCOUT', 'Flank Scout'), ('SCOUT', 'Scout'), ('P_SOLLY', 'Pocket Soldier'), ('ROAMER', 'Roamer'), ('SOLDIER', 'Soldier'), ('PYRO', 'Pyro'), ('DEMO', 'Demoman'), ('HEAVY', 'Heavy'), ('ENGIE', 'Engineer'), ('MEDIC', 'Medic'), ('SNIPER', 'Sniper'), ('SPY', 'Spy')], max_length=7)),
('main', models.BooleanField(default=True)),
],
),
migrations.AddField(
model_name='playerinfo_team',
name='team',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.team'),
),
migrations.AddField(
model_name='playerinfo_team',
name='player_info',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.playerinfo'),
),
migrations.AddField(
model_name='playerinfo',
name='team',
field=models.ManyToManyField(through='api.PlayerInfo_Team', to='api.team'),
),
migrations.AlterUniqueTogether(
name='playerinfo_team',
unique_together={('player_info', 'team')},
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 5.1.2 on 2024-10-24 02:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='playerinfo_team',
name='team_role',
field=models.CharField(choices=[('PL', 'Player'), ('CM', 'Coach/Mentor'), ('TL', 'Team Leader')], default='PL', max_length=2),
),
]

View File

@ -0,0 +1,36 @@
# Generated by Django 5.1.2 on 2024-10-24 02:18
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0002_alter_playerinfo_team_team_role'),
]
operations = [
migrations.CreateModel(
name='PlayerMasterAvailability',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('start_time', models.DateTimeField()),
('playerinfo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.playerinfo')),
],
options={
'constraints': [models.UniqueConstraint(fields=('playerinfo', 'start_time'), name='unique_master_availability')],
},
),
migrations.CreateModel(
name='PlayerTeamAvailability',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('start_time', models.DateTimeField()),
('playerinfo_team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.playerinfo_team')),
],
options={
'constraints': [models.UniqueConstraint(fields=('playerinfo_team', 'start_time'), name='unique_team_availability')],
},
),
]

View File

@ -0,0 +1,39 @@
# Generated by Django 5.1.2 on 2024-10-24 02:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0003_playermasteravailability_playerteamavailability'),
]
operations = [
migrations.RemoveConstraint(
model_name='playermasteravailability',
name='unique_master_availability',
),
migrations.RemoveConstraint(
model_name='playerteamavailability',
name='unique_team_availability',
),
migrations.RenameField(
model_name='playermasteravailability',
old_name='playerinfo',
new_name='player_info',
),
migrations.RenameField(
model_name='playerteamavailability',
old_name='playerinfo_team',
new_name='player_info_team',
),
migrations.AddConstraint(
model_name='playermasteravailability',
constraint=models.UniqueConstraint(fields=('player_info', 'start_time'), name='unique_master_availability'),
),
migrations.AddConstraint(
model_name='playerteamavailability',
constraint=models.UniqueConstraint(fields=('player_info_team', 'start_time'), name='unique_team_availability'),
),
]

View File

@ -0,0 +1,121 @@
from typing import override
from django.db import models
from cpkmodel import CPkModel
from django.db.models.constraints import UniqueConstraint
class Team(models.Model):
team_name = models.CharField(max_length=63)
@override
def __str__(self) -> str:
return str(self.team_name)
class Player(models.Model):
steam_id = models.BigIntegerField(primary_key=True)
name = models.CharField(max_length=63)
@override
def __str__(self) -> str:
return f"{self.name}#{self.steam_id}"
class PlayerInfo(models.Model):
player = models.OneToOneField(
Player,
on_delete=models.CASCADE,
null=False,
primary_key=True
)
team = models.ManyToManyField(Team, through="PlayerInfo_Team")
@override
def __str__(self) -> str:
return str(self.player)
class PlayerInfo_Team(models.Model):
class TeamRole(models.TextChoices):
PLAYER = "PL", "Player"
COACH_MENTOR = "CM", "Coach/Mentor"
TEAM_LEADER = "TL", "Team Leader"
player_info = models.ForeignKey(PlayerInfo, on_delete=models.CASCADE)
team = models.ForeignKey(Team, on_delete=models.CASCADE, null=True)
team_role = models.CharField(
max_length=2,
choices=TeamRole.choices,
default=TeamRole.PLAYER
)
created_at = models.DateTimeField(auto_now_add=True)
@override
def __str__(self) -> str:
return f"{self.player_info} in {self.team} as {self.team_role}"
class Meta:
unique_together = (("player_info", "team"),)
class PlayerRole(models.Model):
class Role(models.TextChoices):
P_SCOUT = "P_SCOUT", "Pocket Scout"
F_SCOUT = "F_SCOUT", "Flank Scout"
SCOUT = "SCOUT", "Scout"
P_SOLLY = "P_SOLLY", "Pocket Soldier"
ROAMER = "ROAMER", "Roamer"
SOLDIER = "SOLDIER", "Soldier"
PYRO = "PYRO", "Pyro"
DEMO = "DEMO", "Demoman"
HEAVY = "HEAVY", "Heavy"
ENGIE = "ENGIE", "Engineer"
MEDIC = "MEDIC", "Medic"
SNIPER = "SNIPER", "Sniper"
SPY = "SPY", "Spy"
playerinfo_team = models.ForeignKey(
PlayerInfo_Team,
on_delete=models.CASCADE,
primary_key=True,
)
player_role = models.CharField(
max_length=7,
choices=Role.choices,
)
main = models.BooleanField(default=True)
@override
def __str__(self) -> str:
return f"{self.playerinfo_team.player_info} ({self.player_role} for {self.playerinfo_team.team})"
class PlayerTeamAvailability(models.Model):
player_info_team = models.ForeignKey(PlayerInfo_Team, on_delete=models.CASCADE)
date = models.DateField()
hour = models.SmallIntegerField()
class Meta:
constraints = [
UniqueConstraint(fields=[
"player_info_team",
"start_time"
], name="unique_team_availability")
]
@override
def __str__(self) -> str:
return f"{self.player_info_team} available on {self.start_time}"
class PlayerMasterAvailability(models.Model):
player_info = models.ForeignKey(PlayerInfo, on_delete=models.CASCADE)
date = models.DateField()
hour = models.SmallIntegerField()
class Meta:
constraints = [
UniqueConstraint(fields=[
"player_info",
"start_time"
], name="unique_master_availability")
]
@override
def __str__(self) -> str:
return f"{self.player_info} available on {self.start_time}"

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@ -37,6 +37,8 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'api',
]
MIDDLEWARE = [

View File

@ -18,5 +18,6 @@ from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path("admin/", admin.site.urls),
path("/", admin.site.urls),
]