-
Notifications
You must be signed in to change notification settings - Fork 940
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
Solution #1016
base: master
Are you sure you want to change the base?
Solution #1016
Changes from all commits
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,32 @@ | ||
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) | ||
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. The |
||
race = models.ForeignKey(Race, on_delete=models.CASCADE, | ||
related_name="skill_set") | ||
|
||
|
||
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) | ||
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. The |
||
race = models.ForeignKey(Race, | ||
on_delete=models.CASCADE, | ||
related_name="player_set") | ||
guild = models.ForeignKey(Guild, | ||
on_delete=models.SET_NULL, | ||
null=True, | ||
blank=True,) | ||
created_at = models.DateTimeField(auto_now_add=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,45 @@ | ||
from django.db.models import ForeignKey # noqa: F401 | ||
import init_django_orm # noqa: F401 | ||
|
||
import json | ||
from db.models import Race, Skill, Player, Guild | ||
|
||
|
||
def main() -> None: | ||
pass | ||
with open("players.json") as players_file: | ||
players = json.load(players_file) | ||
|
||
for name, value in players.items(): | ||
|
||
race, _ = Race.objects.get_or_create( | ||
name=value["race"]["name"], | ||
description=value["race"]["description"] | ||
) | ||
|
||
guild = None | ||
if value["guild"] is not None: | ||
guild, _ = Guild.objects.get_or_create( | ||
name=value["guild"]["name"], | ||
description=( | ||
value["guild"]["description"] | ||
if value["guild"]["description"] | ||
else None | ||
), | ||
) | ||
|
||
for skill in value["race"]["skills"]: | ||
Skill.objects.get_or_create( | ||
name=skill["name"], | ||
bonus=skill["bonus"], | ||
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. Ensure that the |
||
race=race, | ||
) | ||
|
||
Player.objects.create( | ||
nickname=name, | ||
email=value["email"], | ||
bio=value["bio"], | ||
race=race, | ||
guild=guild, | ||
) | ||
|
||
|
||
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.
The
bonus
field is currently aCharField
. If this field is meant to store numerical values, consider usingIntegerField
orFloatField
instead.