Skip to content
Open

Develop #1707

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-03 20:30

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 violation: Missing related_name on ForeignKey fields. Add related_name to: Skill.race (line 11), Player.race (line 23), and Player.guild (line 24) to enable reverse access from related models.

]

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

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 violation: Missing related_name on this ForeignKey field.

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, null=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='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')),
],
),
]
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, null=True)


class Skill(models.Model):
name = models.CharField(max_length=255, unique=True)
bonus = 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 #3 violation: This ForeignKey is missing the required related_name parameter. Add related_name='skills' to allow reverse access from Race to Skill.

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.

Checklist item #5 violation: Direct dictionary access is used (data['race']['name']). Use .get() method instead: data.get('race', {}).get('name') to safely check if keys exist.


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 (data['race']['description']). Use .get() method instead to safely handle missing keys.

class Guild(models.Model):
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: Direct dictionary access is used (data['race']['skills']). Use .get() method instead to safely handle 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.

Checklist item #5 violation: Direct dictionary access is used (skill_data['name']). Use .get() method instead.

class Player(models.Model):
nickname = models.CharField(max_length=255, unique=True)
Comment thread
RustamHadoiev24 marked this conversation as resolved.
email = models.EmailField(max_length=255)
bio = models.CharField(max_length=255)
race = models.ForeignKey(
Race,
on_delete=models.CASCADE,
related_name="players"
)
guild = models.ForeignKey(
Guild,
on_delete=models.SET_NULL,
null=True,
related_name="players"
)
created_at = models.DateTimeField(auto_now_add=True)
36 changes: 35 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
import json
import init_django_orm # noqa: F401

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


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

for nickname, data in players_data.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: Missing related_name on race ForeignKey. Add related_name='skills' to allow access from Race to related Skills.

race_data = data.get("race", {})
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 instead of direct dictionary access. Replace data["race"]["name"] with data.get("race", {}).get("name") to safely handle missing keys.

name=race_data.get("name"),
defaults={"description": race_data.get("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 instead of direct dictionary access for safe key lookup.

for skill_data in race_data.get("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 instead of direct dictionary access for safe key lookup.

name=skill_data.get("name"),
race=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 instead of direct dictionary access for safe key lookup.

defaults={"bonus": skill_data.get("bonus")}
)

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 race ForeignKey. Add related_name='players' to allow access from Race to related Players.

guild = None
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 guild ForeignKey. Add related_name='players' to allow access from Guild to related Players.

guild_data = data.get("guild")
if guild_data:
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 instead of direct dictionary access for safe key lookup.

name=guild_data.get("name"),
defaults={"description": guild_data.get("description")}
)

Player.objects.get_or_create(
nickname=nickname,
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 #5 violation: Use .get() method instead of direct dictionary access for safe key lookup.

"email": data.get("email"),
"bio": data.get("bio"),
"race": race,
"guild": guild
}
)


if __name__ == "__main__":
Expand Down
Loading