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.5 on 2026-05-07 13:14

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unused import: ForeignKey is imported from django.db.models but the code uses models.ForeignKey and ForeignKey inconsistently (line 33). Either use the imported ForeignKey directly or remove the import if not needed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The ForeignKey import from django.db.models is unused. The code uses models.ForeignKey instead. Remove this import to clean up the code.

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


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Guild',
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 access instead of checking key existence. Consider using .get() to safely access dictionary values.

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 violation: Direct dictionary access [] is used here. According to the checklist, use .get() method to check whether key is defined in dictionary. This should be player_info["race"].get("skills") to safely access the skills list.

('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 access instead of checking key existence.

),
migrations.CreateModel(
name='Race',
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 #5 violation: Use .get() method for dictionary access instead of checking key existence.

('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.

Direct dictionary access violates checklist item #5. Use player_info.get("race").get("skills") instead of player_info["race"]["skills"] to safely access nested keys.

],
),
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 access instead of checking key existence.

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=254)),
('bio', models.CharField(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 access instead of checking key existence.

('created_at', models.DateTimeField(auto_now_add=True)),
('guild', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='players', 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='skills', to='db.race')),
],
),
]
19 changes: 19 additions & 0 deletions db/migrations/0002_alter_player_guild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 6.0.5 on 2026-05-07 14: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.

The ForeignKey import is unused - models.ForeignKey is used instead. Remove this import.

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


class Migration(migrations.Migration):

dependencies = [
('db', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='player',
name='guild',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='players', to='db.guild'),
),
]
19 changes: 19 additions & 0 deletions db/migrations/0003_alter_player_guild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 6.0.5 on 2026-05-07 14:44

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 import from django.db.models import ForeignKey is unused since the code uses models.ForeignKey instead.

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 import is unused - line 17 uses models.ForeignKey not the imported ForeignKey. Either remove this import or use ForeignKey directly without the models. prefix.

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


class Migration(migrations.Migration):

dependencies = [
('db', '0002_alter_player_guild'),
]

operations = [
migrations.AlterField(
model_name='player',
name='guild',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='players', to='db.guild'),
),
]
39 changes: 39 additions & 0 deletions db/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
from django.db import models
from django.db.models import 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.

The ForeignKey import is unused - the code uses models.ForeignKey instead. Remove this import for cleaner code as noted in previous review.



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,
related_name="skills"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Direct dictionary access ["race"] violates checklist item #5. Use player_info.get("race") instead to safely access the nested race dictionary before calling .get("name").



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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EmailField defaults to max_length=254, but the requirements specify max_length=255. Add explicit max_length=255 to match task requirements.

email = models.EmailField()
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.

Direct dictionary access ["race"] violates checklist item #5. Change to player_info.get("race").get("skills") or at minimum player_info.get("race")["skills"].

Race,
on_delete=models.CASCADE,
related_name="players"
)
guild = ForeignKey(
Guild,
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 the task requirement for email field to have max_length=255. The migration still shows max_length=254 (Django's default). After updating the model, regenerate migrations to fix this.

on_delete=models.SET_NULL,
related_name="players",
null=True
)
created_at = models.DateTimeField(auto_now_add=True)
37 changes: 36 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
import json

import init_django_orm # noqa: F401

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


def main() -> None:
pass
Race.objects.all().delete()
Skill.objects.all().delete()
Player.objects.all().delete()
Guild.objects.all().delete()
with open("players.json", "r") as file:
player_data = json.load(file)

for player_name, player_info in player_data.items():
player_race, _ = Race.objects.get_or_create(
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 access instead of direct bracket access. The .get() method returns None by default for missing keys.

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 #5: use .get() method for dictionary access. Change player_info["race"] to player_info.get("race") to safely access the 'race' key.

name=player_info["race"]["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 #5 violation: Use .get() method for dictionary access.

defaults={"description": player_info["race"]["description"]}
)

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 access.

if not player_info["guild"]:
player_guild = None
else:
player_guild, _ = Guild.objects.get_or_create(
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 access.

name=player_info["guild"]["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 #5 violation: Use .get() method for dictionary access.

defaults={"description": player_info["guild"]["description"]}
)
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: Direct dictionary access ["skills"] is used here. Use .get() method instead: player_info["race"].get("skills")


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 access.

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 #5: use .get() method for dictionary access. Change player_info["race"]["skills"] to player_info.get("race").get("skills") to safely access nested keys.

for skill in player_info["race"]["skills"]:
Skill.objects.get_or_create(
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 access.

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 #5 violation: Use .get() method for dictionary access.

defaults={"bonus": skill["bonus"], "race": player_race}
)

Player.objects.create(
nickname=player_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 #5 violation: Use .get() method for dictionary access.

email=player_info["email"],
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 access.

bio=player_info["bio"],
race=player_race,
guild=player_guild
)


if __name__ == "__main__":
Expand Down
Loading