diff --git a/db/migrations/0001_initial.py b/db/migrations/0001_initial.py new file mode 100644 index 00000000..0a85258e --- /dev/null +++ b/db/migrations/0001_initial.py @@ -0,0 +1,52 @@ +# Generated by Django 4.0.2 on 2024-11-04 14:48 + +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, verbose_name='This field describes what kind of bonus players can get from it.')), + ('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.race')), + ], + ), + migrations.CreateModel( + name='PlayerMode', + 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, verbose_name='It stores a short description provided by a user about himself/herself.')), + ('created_at', models.DateTimeField(auto_now=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')), + ], + ), + ] diff --git a/db/migrations/0002_player_delete_playermode.py b/db/migrations/0002_player_delete_playermode.py new file mode 100644 index 00000000..2bffb27f --- /dev/null +++ b/db/migrations/0002_player_delete_playermode.py @@ -0,0 +1,29 @@ +# Generated by Django 4.0.2 on 2024-11-04 17:24 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('db', '0001_initial'), + ] + + operations = [ + 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, verbose_name='It stores a short description provided by a user about himself/herself.')), + ('created_at', models.DateTimeField(auto_now=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.DeleteModel( + name='PlayerMode', + ), + ] diff --git a/db/migrations/0003_alter_player_bio_alter_player_created_at_and_more.py b/db/migrations/0003_alter_player_bio_alter_player_created_at_and_more.py new file mode 100644 index 00000000..26973bd6 --- /dev/null +++ b/db/migrations/0003_alter_player_bio_alter_player_created_at_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.0.2 on 2024-11-04 22:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('db', '0002_player_delete_playermode'), + ] + + operations = [ + migrations.AlterField( + model_name='player', + name='bio', + field=models.CharField(max_length=255), + ), + migrations.AlterField( + model_name='player', + name='created_at', + field=models.DateTimeField(auto_now_add=True), + ), + migrations.AlterField( + model_name='skill', + name='bonus', + field=models.CharField(max_length=255), + ), + ] diff --git a/db/models.py b/db/models.py index 137941ff..b0a18843 100644 --- a/db/models.py +++ b/db/models.py @@ -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) + + +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, unique=False) + 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) diff --git a/main.py b/main.py index e71f55d8..3551b6d4 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,40 @@ +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_data = json.load(file) + + for nickname, player_data in players_data.items(): + race_info = player_data.get("race") + race_player, created = Race.objects.get_or_create( + name=race_info.get("name"), + description=race_info.get("description") + ) + skills = race_info.get("skills") + for skill in skills: + Skill.objects.get_or_create( + name=skill.get("name"), + race=race_player, + bonus=skill.get("bonus"), + ) + guild_info = player_data.get("guild") + if guild_info: + guild_player, created = Guild.objects.get_or_create( + name=guild_info.get("name"), + description=guild_info.get("description") + ) + else: + guild_player = None + Player.objects.get_or_create( + nickname=nickname, + email=player_data.get("email"), + bio=player_data.get("bio"), + race=race_player, + guild=guild_player + ) if __name__ == "__main__":