Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions db/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 6.0.5 on 2026-05-13 16:01

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Guild',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
('description', models.TextField(null=True)),
],
),
migrations.CreateModel(
name='Race',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
('description', models.TextField(blank=True)),
],
),
migrations.CreateModel(
name='Player',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nickname', models.CharField(max_length=255, unique=True)),
('email', models.EmailField(max_length=255)),
('bio', models.CharField(max_length=255)),
('created_at', models.DateTimeField(auto_now_add=True)),
('guild', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='guilds', to='db.guild')),
('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='players', to='db.race')),
],
),
migrations.CreateModel(
name='Skill',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
('bonus', models.CharField(max_length=255)),
('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='races', to='db.race')),
],
),
]
38 changes: 38 additions & 0 deletions db/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
from django.db import models


class Race(models.Model):
name = models.CharField(max_length=255, unique=True)
description = models.TextField(blank=True)


class Skill(models.Model):
name = models.CharField(max_length=255, unique=True)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #5 violation: Use .get() method for dictionary key access instead of direct bracket notation. Change player["race"] to player.get("race") to handle missing keys gracefully.

bonus = models.CharField(max_length=255)
race = models.ForeignKey(
Race,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #5 violation: Use .get() method for dictionary key access. Change race["name"] to race.get("name").

on_delete=models.CASCADE,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #5 violation: Use .get() method for dictionary key access. Change race["description"] to race.get("description").

related_name="races"
Comment on lines +11 to +15
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #3 violation: The related_name for Skill.race should be 'skills' (to access skills from a race), not 'races'. The migration file correctly shows related_name='skills', but this model uses 'races'. This mismatch means accessing race.skills won't work as expected.

)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #5 violation: Use .get() method for dictionary key access. Change race["skills"] to race.get("skills").


class Guild(models.Model):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #5 violation: Use .get() method for dictionary key access. Change skill["name"] to skill.get("name").

name = models.CharField(max_length=255, unique=True)
description = models.TextField(null=True)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #5 violation: Use .get() method for dictionary key access. Change skill["bonus"] to skill.get("bonus").



class Player(models.Model):
nickname = models.CharField(max_length=255, unique=True)
email = models.EmailField(max_length=255)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #5 violation: Use .get() method for dictionary key access. Change player["guild"] to player.get("guild").

bio = models.CharField(max_length=255)
race = models.ForeignKey(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #5 violation: Use .get() method for dictionary key access. Change guild["name"] to guild.get("name").

Race,
on_delete=models.CASCADE,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #5 violation: Use .get() method for dictionary key access. Change guild["description"] to guild.get("description").

related_name="players"
Comment on lines +27 to +31
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #3 violation: The related_name for Player.race should be 'players' (to access players from a race), not 'races'. The migration file correctly shows related_name='races', but this model uses 'players'. This mismatch will cause the migration and models to be out of sync.

)
guild = models.ForeignKey(
Guild,
on_delete=models.SET_NULL,
related_name="guilds",
null=True
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist item #5 violation: Use .get() method for dictionary key access. Change player["email"] to player.get("email").

created_at = models.DateTimeField(auto_now_add=True)
41 changes: 39 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
import init_django_orm # noqa: F401

import json
from db.models import Race, Skill, Player, Guild


def main() -> None:
pass
with open("players.json", "r") as file:
players = json.load(file)

for nickname, player in players.items():
race = player.get("race")
race_obj, created = Race.objects.get_or_create(
name=race.get("name"),
defaults={
"description": race.get("description")
}
)
for skill in race.get("skills"):
Skill.objects.get_or_create(
name=skill.get("name"),
defaults={
"bonus": skill.get("bonus"),
"race": race_obj
}
)
guild = player.get("guild")
if guild:
guild_obj, created = Guild.objects.get_or_create(
name=guild.get("name"),
defaults={
"description": guild.get("description")
}
)
else:
guild_obj = None
Player.objects.get_or_create(
nickname=nickname,
defaults={
"email": player.get("email"),
"bio": player.get("bio"),
"race": race_obj,
"guild": guild_obj
}
)


if __name__ == "__main__":
Expand Down
Loading