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
28 changes: 27 additions & 1 deletion db/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
from django.db import models
from django.db import models # noqa: 401
from django.forms.fields import CharField
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. Django's CharField is not needed here since the code uses models.CharField. Remove this line.



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.

Checklist item #3 violation: Missing related_name on this ForeignKey field. Add a related_name parameter to enable access to related models from the Race side.



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

Checklist item #3 violation: Missing related_name on this ForeignKey field. Add a related_name parameter to enable access to related models from the Race side.

guild = models.ForeignKey(Guild, on_delete=models.SET_NULL, 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 #3 violation: Missing related_name on this ForeignKey field. Add a related_name parameter to enable access to related models from the Guild side.

created_at = models.DateTimeField(auto_now_add=True)
30 changes: 29 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
import json
import init_django_orm # noqa: F401
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 never used. The models use models.CharField from the django.db import, not CharField from django.forms.fields. Remove this unused import.


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


def main() -> None:
pass
with open("players.json", "r") as file:
players_info = json.load(file)
for nickname, user_info in players_info.items():
race_obj, _ = Race.objects.get_or_create(
name=user_info["race"]["name"],
defaults={"description": user_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.

Missing related_name parameter. Per checklist item #3, add related_name='skills' to allow reverse access from Race to Skill.

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

Missing related_name parameter. Per checklist item #3, add related_name='players' to allow reverse access from Race to Player.

name=user_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.

Missing related_name parameter. Per checklist item #3, add related_name='members' (or similar) to allow reverse access from Guild to Player.

defaults={"description": user_info["guild"]["description"]}
)
Player.objects.create(
nickname=nickname,
email=user_info["email"],
bio=user_info["bio"],
race=race_obj,
guild=guild_obj
)


if __name__ == "__main__":
Expand Down
Loading