Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
30 changes: 30 additions & 0 deletions db/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
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,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use .get() method instead of bracket notation for dictionary access. This violates checklist item #5 which requires using .get() to safely check if keys exist.

related_name="skills")


class Guild(models.Model):
name = models.CharField(max_length=255, unique=True)
description = models.TextField(blank=True, 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.

Use .get() method instead of bracket notation for dictionary access per checklist item #5.


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use .get() method instead of bracket notation for dictionary access per checklist item #5.


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

Choose a reason for hiding this comment

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

Use .get() method instead of bracket notation for dictionary access per checklist item #5.

related_name="players")
guild = models.ForeignKey(Guild,
on_delete=models.SET_NULL,
null=True,
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.

Missing related_name='members' on Player.guild ForeignKey. This was highlighted in the previous review and is required by checklist item #3 to access players from the Guild side.

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

for nickname, data in players.items():
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.

Missing related_name on the race ForeignKey - violates CHECKLIST ITEM #3. Add related_name='skills' to enable access from Race to related Skill objects.

name=data["race"]["name"],
defaults={"description": data["race"].get("description", "")}
)

for skill_data in data["race"].get("skills", []):
Skill.objects.get_or_create(
name=skill_data["name"],
race=race,
defaults={"bonus": skill_data["bonus"]}
)

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.

Missing related_name on the race ForeignKey - violates CHECKLIST ITEM #3. Add related_name='players' to enable access from Race to related Player objects.

if data.get("guild"):
guild, _ = Guild.objects.get_or_create(
name=data["guild"]["name"],
defaults={"description": data["guild"].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.

Missing related_name='members' on Player.guild ForeignKey. This was highlighted in the previous review as required by checklist item #3 to enable access from the 'Many' side of the relationship.

)

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


if __name__ == "__main__":
Expand Down
Loading