-
Notifications
You must be signed in to change notification settings - Fork 1.5k
'Solution' #1721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
'Solution' #1721
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
|
|
||
| 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checklist item #3 violation: Missing |
||
|
|
||
|
|
||
| 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checklist item #3 violation: Missing |
||
| guild = models.ForeignKey(Guild, on_delete=models.SET_NULL, null=True) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checklist item #3 violation: Missing |
||
| created_at = models.DateTimeField(auto_now_add=True) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,38 @@ | ||
| import json | ||
| import init_django_orm # noqa: F401 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This import is never used. The models use |
||
|
|
||
| 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"]} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
| ) | ||
| 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( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
| name=user_info["guild"]["name"], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
| 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__": | ||
|
|
||
There was a problem hiding this comment.
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.