-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Solution #1719
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 #1719
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.5 on 2026-05-09 12:00 | ||
|
|
||
| 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)), | ||
| ('descriptions', models.TextField(null=True)), | ||
| ], | ||
| ), | ||
| migrations.CreateModel( | ||
| name='Raise', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('name', models.CharField(max_length=255, unique=True)), | ||
| ('descriptions', 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, unique=True)), | ||
| ('bio', models.CharField(max_length=255)), | ||
| ('created_at', models.DateTimeField(auto_now_add=True)), | ||
| ('guild', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.guild')), | ||
| ('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.raise')), | ||
| ], | ||
| ), | ||
| 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.raise')), | ||
| ], | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Generated by Django 6.0.5 on 2026-05-09 13:25 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('db', '0001_initial'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RenameModel( | ||
| old_name='Raise', | ||
| new_name='Race', | ||
| ), | ||
| migrations.RenameField( | ||
| model_name='guild', | ||
| old_name='descriptions', | ||
| new_name='description', | ||
| ), | ||
| migrations.RenameField( | ||
| model_name='race', | ||
| old_name='descriptions', | ||
| new_name='description', | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='player', | ||
| name='email', | ||
| field=models.EmailField(max_length=255), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='player', | ||
| name='guild', | ||
| field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='db.guild'), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Generated by Django 6.0.5 on 2026-05-09 13:41 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('db', '0002_rename_raise_race_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='player', | ||
| name='guild', | ||
| field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='players', to='db.guild'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='player', | ||
| name='race', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='players', to='db.race'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='skill', | ||
| name='race', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='skills', to='db.race'), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,42 @@ | ||
| 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, | ||
| related_name="skills" | ||
| ) | ||
|
|
||
|
|
||
| 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, | ||
| related_name="players" | ||
| ) | ||
|
|
||
| guild = models.ForeignKey( | ||
| Guild, | ||
| on_delete=models.SET_NULL, | ||
| null=True, | ||
| related_name="players" | ||
| ) | ||
|
|
||
| created_at = models.DateTimeField(auto_now_add=True) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,54 @@ | ||
| import json | ||
|
|
||
| import init_django_orm # noqa: F401 | ||
|
|
||
| from db.models import Race, Skill, Player, Guild | ||
|
|
||
|
|
||
| def main() -> None: | ||
| pass | ||
| with open("players.json", "r") as file: | ||
| players = json.load(file) | ||
|
|
||
| for nickname, player_data in players.items(): | ||
|
|
||
| race_data = player_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( | ||
| name=skill_data["name"], | ||
| defaults={ | ||
| "bonus": skill_data["bonus"], | ||
| "race": race | ||
| } | ||
| ) | ||
|
|
||
| guild_data = player_data.get("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. Missing |
||
| guild = None | ||
|
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 |
||
| 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_data["email"], | ||
| "bio": player_data["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.
Missing
related_nameon ForeignKey to Race. This is required by checklist item #3 to enable reverse access from Race to its skills (e.g., race.skills.all()). Addrelated_name='skills'.