-
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 #1032
base: master
Are you sure you want to change the base?
solution #1032
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Generated by Django 4.0.2 on 2024-11-05 16:20 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Guild', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255, unique=True)), | ||
('description', models.TextField(null=True)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Race', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255, unique=True)), | ||
('description', models.TextField(blank=True)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Skill', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255, unique=True)), | ||
('bonus', models.CharField(max_length=255)), | ||
('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.race')), | ||
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 ForeignKey reference 'to='db.race'' might be incorrect. Ensure that 'db' is the correct app label. If the app is named differently, replace 'db' with the correct app name. |
||
], | ||
), | ||
migrations.CreateModel( | ||
name='Player', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('nickname', models.CharField(max_length=255, unique=True)), | ||
('email', models.EmailField(max_length=255)), | ||
('bio', models.CharField(max_length=255)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('guild', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='db.guild')), | ||
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 ForeignKey reference to 'db.guild' might be incorrect if 'db' is not the app label. Ensure that 'db' is the correct app label for the Guild model. 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 ForeignKey reference 'to='db.guild'' might be incorrect. Ensure that 'db' is the correct app label. If the app is named differently, replace 'db' with the correct app name. |
||
('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.race')), | ||
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 ForeignKey reference to 'db.race' might be incorrect if 'db' is not the app label. Ensure that 'db' is the correct app label for the Race model. 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 ForeignKey reference 'to='db.race'' might be incorrect. Ensure that 'db' is the correct app label. If the app is named differently, replace 'db' with the correct app name. |
||
], | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
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) | ||
|
||
|
||
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) | ||
guild = models.ForeignKey(Guild, on_delete=models.SET_NULL, null=True) | ||
created_at = models.DateTimeField(auto_now_add=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,36 @@ | ||
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 players_file: | ||
players = json.load(players_file) | ||
|
||
for player_name, player_info in players.items(): | ||
race_data = player_info["race"] | ||
race, created = Race.objects.get_or_create( | ||
name=race_data["name"], | ||
defaults={"description": race_data["description"]}) | ||
for skill_data in race_data["skills"]: | ||
Skill.objects.get_or_create( | ||
name=skill_data["name"], | ||
defaults={"bonus": skill_data["bonus"], "race": race}) | ||
guild = None | ||
if player_info["guild"]: | ||
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 'player_info["guild"]' is checked for None or empty values correctly. If 'guild' can be an empty string or another falsy value, consider using a more explicit check like 'if player_info.get("guild") is not None:' to avoid potential issues. |
||
guild_data = player_info["guild"] | ||
guild, created = Guild.objects.get_or_create( | ||
name=guild_data["name"], | ||
defaults={"description": guild_data["description"]} | ||
) | ||
|
||
Player.objects.get_or_create(nickname=player_name, | ||
defaults={ | ||
"email": player_info["email"], | ||
"bio": player_info["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 ForeignKey reference to 'db.race' might be incorrect if 'db' is not the app label. Ensure that 'db' is the correct app label for the Race model.