-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Solution #1710
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 #1710
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 6.0.4 on 2026-05-04 01:34 | ||
|
|
||
| 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. Checklist item #3: This ForeignKey is 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. Checklist item #3: This ForeignKey is 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)), | ||
| ('guild', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='db.guild')), | ||
| ('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)), | ||
| ('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) | ||
| race = models.ForeignKey(Race, on_delete=models.CASCADE) | ||
|
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. 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) | ||
|
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. Checklist item #3 violation: Missing |
||
| guild = models.ForeignKey(Guild, on_delete=models.SET_NULL, null=True) | ||
|
Comment on lines
+24
to
+25
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,52 @@ | ||
| 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 file: | ||
| players = json.load(file) | ||
|
|
||
| for nickname, player in players.items(): | ||
|
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: ForeignKey field is missing |
||
| race_data = player.get("race") | ||
|
|
||
| race, _ = Race.objects.get_or_create( | ||
| name=race_data["name"], | ||
| defaults={ | ||
| "description": race_data.get("description", "") | ||
| } | ||
| ) | ||
|
|
||
| for skill in race_data.get("skills", []): | ||
| Skill.objects.get_or_create( | ||
| name=skill["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. Checklist item #3 violation: ForeignKey field is missing |
||
| defaults={ | ||
|
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: ForeignKey field is missing |
||
| "bonus": skill["bonus"], | ||
| "race": race | ||
| } | ||
| ) | ||
|
|
||
| guild = None | ||
| guild_data = player.get("guild") | ||
|
|
||
| if guild_data: | ||
| guild, _ = Guild.objects.get_or_create( | ||
| name=guild_data["name"], | ||
| defaults={ | ||
| "description": guild_data.get("description") | ||
| } | ||
| ) | ||
|
|
||
| Player.objects.get_or_create( | ||
| nickname=nickname, | ||
| defaults={ | ||
| "email": player["email"], | ||
| "bio": player["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.
Checklist item #3: This ForeignKey is missing
related_name. Add a related_name (e.g.,related_name='skills') to allow reverse access from Race to Skills.