Skip to content
Open

fix3 #1722

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 10:43

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


class Migration(migrations.Migration):

initial = True

dependencies = [
]

Comment on lines +11 to +13
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing related_name on ForeignKey field (checklist item #3 requires this for all ForeignKey fields to access related models on Many side)

Comment on lines +11 to +13
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing related_name='skills' - checklist item #3 requires this to access related skills via race_obj.skills.all()

Comment on lines +11 to +13
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: Skill.race ForeignKey is missing related_name='skills'. This parameter is required to allow accessing skills via race_obj.skills.all().

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(blank=True, null=True)),
],
),
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.

Missing related_name on ForeignKey field (checklist item #3 requires this for all ForeignKey fields to access related models on Many side)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing related_name='players' - checklist item #3 requires this to access related players via race_obj.players.all()

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: Player.race ForeignKey is missing related_name='players'. This parameter is required to allow accessing players via race_obj.players.all().

('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)),
Comment on lines +26 to +28
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing related_name on ForeignKey field (checklist item #3 requires this for all ForeignKey fields to access related models on Many side)

Comment on lines +26 to +28
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing related_name='players' - checklist item #3 requires this to access related players via guild_obj.players.all()

Comment on lines +26 to +28
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: Player.guild ForeignKey is missing related_name='players'. This parameter is required to allow accessing players via guild_obj.players.all().

],
),
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(blank=True, max_length=255)),
('created_at', models.DateTimeField(auto_now_add=True)),
('guild', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='db.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.

Migration file must be updated to include related_name='players' for the guild ForeignKey

('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.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.

Migration file must be updated to include related_name='players' for the race ForeignKey

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

Choose a reason for hiding this comment

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

Migration file must be updated to include related_name='skills' for the race ForeignKey

('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.race')),
Comment on lines +39 to +49
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Migration file needs to be regenerated after adding related_name parameters to the models. The ForeignKey fields in this migration are missing the related_name attribute.

],
),
]
29 changes: 29 additions & 0 deletions db/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
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 +12 to +13
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. Required to access related models from the Race side (e.g., race_obj.skill_set). Add related_name='skills' to this field.

Comment on lines +11 to +13
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 related_name='skills'. Add this parameter to allow accessing skills via race_obj.skills.all()

Comment on lines +11 to +13
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing related_name='skills' on Skill.race ForeignKey - violates CHECKLIST ITEM #3

)


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


class Player(models.Model):
nickname = models.CharField(max_length=255, unique=True)
email = models.EmailField(max_length=255, unique=False)
bio = models.CharField(max_length=255, 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 #3 violation: This ForeignKey is missing related_name='players'. Add this parameter to allow accessing players via race_obj.players.all()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing related_name='players' on Player.race ForeignKey - violates CHECKLIST ITEM #3

race = models.ForeignKey(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 #3 VIOLATION: Missing related_name on race ForeignKey. Required to access related models from the Race side (e.g., race_obj.player_set). Add related_name='players' to this field.

guild = models.ForeignKey(
Guild, on_delete=models.SET_NULL, null=True, blank=True
Comment on lines +27 to +28
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. Required to access related models from the Guild side (e.g., guild_obj.player_set). Add related_name='players' to this field.

Comment on lines +26 to +28
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 related_name='players'. Add this parameter to allow accessing players via guild_obj.players.all()

Comment on lines +26 to +28
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing related_name='players' on Player.guild ForeignKey - violates CHECKLIST ITEM #3

)
created_at = models.DateTimeField(auto_now_add=True)
37 changes: 35 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
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 f:
all_players_data = json.load(f)

for player_nickname, player_details in all_players_data.items():
race_obj, _ = Race.objects.get_or_create(
name=player_details["race"]["name"],
defaults={
Comment on lines +11 to +13
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing related_name='skills' - CHECKLIST ITEM #3 requires adding related_name to all ForeignKey fields to access related models (e.g., race_obj.skills.all())

Comment on lines +11 to +13
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='skills' on this ForeignKey field. This is required to access skills via race_obj.skills.all().

"description": player_details["race"].get("description", "")
}
)

for skill_info in player_details["race"]["skills"]:
Skill.objects.get_or_create(
name=skill_info["name"],
race=race_obj,
defaults={"bonus": skill_info.get("bonus", "")}
)
guild_obj = None
if player_details.get("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.

Missing related_name='players' - CHECKLIST ITEM #3 requires adding related_name to all ForeignKey fields to access related models (e.g., race_obj.players.all())

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='players' on this ForeignKey field. This is required to access players via race_obj.players.all().

guild_obj, _ = Guild.objects.get_or_create(
name=player_details["guild"]["name"],
defaults={
Comment on lines +26 to +28
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing related_name='players' - CHECKLIST ITEM #3 requires adding related_name to all ForeignKey fields to access related models (e.g., guild_obj.players.all())

Comment on lines +26 to +28
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='players' on this ForeignKey field. This is required to access players via guild_obj.players.all().

"description": player_details["guild"].get("description")}
)

Player.objects.get_or_create(
nickname=player_nickname,
defaults={
"email": player_details["email"],
"bio": player_details.get("bio", ""),
"race": race_obj,
"guild": guild_obj,
}
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Migration needs updating after adding related_name to Player.guild ForeignKey in models.py


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Migration needs updating after adding related_name to Player.race ForeignKey in models.py


if __name__ == "__main__":
Expand Down
Loading