-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 #1145
base: master
Are you sure you want to change the base?
Solution #1145
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 5.1.1 on 2025-01-24 18:04 | ||
|
||
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(blank=True, 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='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(on_delete=django.db.models.deletion.DO_NOTHING, 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)), | ||
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(on_delete=django.db.models.deletion.CASCADE, to='db.race')), | ||
], | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 5.1.1 on 2025-01-24 18:31 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('db', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='player', | ||
name='guild', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='members', 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 5.1.1 on 2025-01-24 18:57 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('db', '0002_alter_player_guild_alter_player_race_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='player', | ||
name='guild', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='members', to='db.guild'), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 5.1.1 on 2025-01-24 18:58 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('db', '0003_alter_player_guild'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='skill', | ||
name='race', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.race'), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
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 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) | ||
|
||
|
||
class Guild(models.Model): | ||
name = models.CharField(max_length=255, unique=True) | ||
description = models.TextField(blank=True, null=True) | ||
|
||
|
||
class Player(models.Model): | ||
nickname = models.CharField(max_length=255, unique=True) | ||
email = models.EmailField(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. Consider adding 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. Consider making the |
||
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, | ||
related_name="members", | ||
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,41 @@ | ||
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 file: | ||
player_data = json.load(file) | ||
|
||
for nickname, data in player_data.items(): | ||
race, created_race = Race.objects.get_or_create( | ||
name=data["race"]["name"], | ||
description=data["race"]["description"], | ||
) | ||
|
||
for skills_data in data["race"]["skills"]: | ||
Skill.objects.get_or_create( | ||
name=skills_data["name"], | ||
bonus=skills_data["bonus"], | ||
race=race, | ||
) | ||
|
||
if data["guild"]: | ||
guild, created_guild = Guild.objects.get_or_create( | ||
name=data["guild"]["name"], | ||
description=data["guild"].get("description", "") | ||
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. When using 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. Consider using |
||
) | ||
else: | ||
guild = None | ||
|
||
player, created = Player.objects.get_or_create( | ||
nickname=nickname, | ||
email=data.get("email"), | ||
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 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 |
||
bio=data.get("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.
Consider making the
email
field unique to avoid duplicate entries. This can be done by addingunique=True
to theEmailField
.