Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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-16 10:20

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


class Migration(migrations.Migration):

initial = True

dependencies = [
Comment thread
bijirin marked this conversation as resolved.
]

Comment thread
bijirin marked this conversation as resolved.
operations = [
Comment thread
bijirin marked this conversation as resolved.
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)),
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 requires using .get() method for dictionary access. Replace skill["name"] with the .get() pattern.

('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 requires using .get() method for dictionary access. Replace skill["bonus"] with the .get() pattern.

],
),
migrations.CreateModel(
Comment thread
bijirin marked this conversation as resolved.
name='Race',
Comment thread
bijirin marked this conversation as resolved.
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)),
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 requires using .get() method for dictionary access. Replace value["guild"]["name"] with the .get() pattern.

],
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 requires using .get() method for dictionary access. Replace value["guild"]["description"] with the .get() pattern.

),
migrations.CreateModel(
name='Player',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
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 requires using .get() method for dictionary access. Replace value["email"] with the .get() pattern.

('nickname', 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 requires using .get() method for dictionary access. Replace value["bio"] with the .get() pattern.

('email', models.EmailField(max_length=254)),
('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 thread
bijirin marked this conversation as resolved.
Outdated


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(unique=False)
bio = models.CharField(max_length=255)
race = models.ForeignKey(Race, on_delete=models.CASCADE)
Comment thread
bijirin marked this conversation as resolved.
Outdated
guild = models.ForeignKey(Guild, on_delete=models.SET_NULL, null=True)
Comment thread
bijirin marked this conversation as resolved.
Outdated
created_at = models.DateTimeField(auto_now_add=True)
34 changes: 33 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
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 key, value 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.

This violates checklist item #3: ForeignKey fields must have related_name parameter for reverse access to related models from the Race side. Add something like related_name='skills'.

player_race, created = Race.objects.get_or_create(
name=value["race"]["name"],
description=value["race"]["description"],
)

for skill in value["race"]["skills"]:
Skill.objects.get_or_create(
name=skill["name"],
bonus=skill["bonus"],
race=player_race,
)

Comment thread
bijirin marked this conversation as resolved.
if value["guild"] is None:
Comment thread
bijirin marked this conversation as resolved.
player_guild = None
else:
player_guild, created = Guild.objects.get_or_create(
name=value["guild"]["name"],
description=value["guild"]["description"],
)

Player.objects.get_or_create(
nickname=key,
email=value["email"],
bio=value["bio"],
race=player_race,
guild=player_guild,
)


if __name__ == "__main__":
Expand Down
Loading