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.4 on 2026-05-04 01:34

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


class Migration(migrations.Migration):

initial = True

dependencies = [
]
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: This ForeignKey is missing related_name. Add a related_name (e.g., related_name='skills') to allow reverse access from Race to Skills.


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',
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: This ForeignKey is missing related_name. Add a related_name (e.g., related_name='players') to allow reverse access from Race to Players.

fields=[
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: This ForeignKey is missing related_name. Add a related_name (e.g., related_name='players') to allow reverse access from Guild to Players.

('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, to='db.guild')),
('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, 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, to='db.race')),
],
),
]
25 changes: 25 additions & 0 deletions db/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
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)
bonus = models.CharField(max_length=255)
race = models.ForeignKey(Race, on_delete=models.CASCADE)
Comment on lines +11 to +12
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: Missing related_name on this ForeignKey. Add related_name='skills' to allow reverse access from Race to Skill model.



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


class Player(models.Model):
nickname = models.CharField(max_length=255, unique=True)
email = models.EmailField(max_length=255)
bio = models.CharField(max_length=255)
race = models.ForeignKey(Race, on_delete=models.CASCADE)
Comment on lines +23 to +24
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: Missing related_name on this ForeignKey. Add related_name='players' to allow reverse access from Race to Player model.

guild = models.ForeignKey(Guild, on_delete=models.SET_NULL, null=True)
Comment on lines +24 to +25
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: Missing related_name on this ForeignKey. Add related_name='players' to allow reverse access from Guild to Player model.

created_at = models.DateTimeField(auto_now_add=True)
44 changes: 43 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,52 @@
import init_django_orm # noqa: F401
import json

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


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

for nickname, player in players.items():
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: ForeignKey field is missing related_name. Add related_name='skills' to allow access to skills from the Race side.

race_data = player.get("race")

race, _ = Race.objects.get_or_create(
name=race_data["name"],
defaults={
"description": race_data.get("description", "")
}
)

for skill in race_data.get("skills", []):
Skill.objects.get_or_create(
name=skill["name"],
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: ForeignKey field is missing related_name. Add related_name='players' to allow access to players from the Race side.

defaults={
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: ForeignKey field is missing related_name. Add related_name='members' to allow access to members from the Guild side.

"bonus": skill["bonus"],
"race": race
}
)

guild = None
guild_data = player.get("guild")

if guild_data:
guild, _ = Guild.objects.get_or_create(
name=guild_data["name"],
defaults={
"description": guild_data.get("description")
}
)

Player.objects.get_or_create(
nickname=nickname,
defaults={
"email": player["email"],
"bio": player["bio"],
"race": race,
"guild": guild
}
)


if __name__ == "__main__":
Expand Down
Loading