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
26 changes: 26 additions & 0 deletions db/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
from django.db import models


class Race(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.

The description field has null=True but the task specifies only blank=True. The task description says 'can be blank', not 'can be null'. Consider removing null=True to match the exact requirement.



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.

Missing related_name on ForeignKey - this violates checklist item #3 which requires adding related_name to access related models from the "Many" side (e.g., related_name='skills' to access skills from a race instance)



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.

Missing related_name on ForeignKey - violates checklist item #3

guild = models.ForeignKey(Guild, on_delete=models.SET_NULL,
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 - violates checklist item #3

null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
36 changes: 34 additions & 2 deletions 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 f:
players = json.load(f)

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

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=race_data["name"],
defaults={"description": race_data.get("description", "")}
)

for skill_data in race_data.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