-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Solution #1711
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 #1711
Changes from 2 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 6.0.4 on 2026-05-04 00:26 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| 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', | ||
|
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 violates checklist item #3: Missing |
||
| fields=[ | ||
|
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 violates checklist item #3: Missing |
||
| ('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='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)), | ||
|
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: The migration is missing |
||
| ('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. CHECKLIST ITEM #3 violation: The migration is missing |
||
| ('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.race')), | ||
| ], | ||
| ), | ||
| 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)), | ||
|
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: The migration is missing |
||
| ('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.race')), | ||
| ], | ||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,26 @@ | ||
| 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. Missing |
||
| 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) | ||
|
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 |
||
| 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. Missing |
||
| 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,11 +1,48 @@ | ||
| import init_django_orm # noqa: F401 | ||
| import json | ||
| import os | ||
|
|
||
| from db.models import Race, Skill, Player, Guild | ||
| import django | ||
|
|
||
| os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_project.settings") | ||
| django.setup() | ||
|
|
||
| from db.models import Guild, Player, Race, Skill # noqa: E402 | ||
|
|
||
|
|
||
| def main() -> None: | ||
|
Comment on lines
11
to
12
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 violates checklist item #3: missing |
||
| pass | ||
| with open("players.json", "r") as f: | ||
| players_data = json.load(f) | ||
|
|
||
| for nickname, data in players_data.items(): | ||
| race_data = data["race"] | ||
| race, _ = Race.objects.get_or_create( | ||
| name=race_data["name"], | ||
| defaults={"description": race_data.get("description", "")} | ||
| ) | ||
|
|
||
| for skill_data in race_data.get("skills", []): | ||
| Skill.objects.get_or_create( | ||
|
Comment on lines
+23
to
+24
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 violates checklist item #3: missing |
||
| name=skill_data["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. This violates checklist item #3: missing |
||
| defaults={ | ||
| "bonus": skill_data["bonus"], | ||
| "race": race, | ||
| } | ||
| ) | ||
|
|
||
| guild = None | ||
| if data.get("guild"): | ||
| guild_data = data["guild"] | ||
| guild, _ = Guild.objects.get_or_create( | ||
| name=guild_data["name"], | ||
| defaults={"description": guild_data.get("description")} | ||
| ) | ||
|
|
||
|
Comment on lines
+38
to
39
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 violates checklist item #3: missing |
||
| if __name__ == "__main__": | ||
| main() | ||
| Player.objects.get_or_create( | ||
|
Comment on lines
39
to
+40
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 violates checklist item #3: missing |
||
| nickname=nickname, | ||
| defaults={ | ||
| "email": data["email"], | ||
| "bio": data.get("bio", ""), | ||
| "race": race, | ||
| "guild": guild, | ||
| } | ||
| ) | ||
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 violates checklist item #3: Missing
related_name='skills'on the ForeignKey. Addrelated_name='skills'to enable access to related models from the Race side.