-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Implemented main() func to transport data from json file to db #1714
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?
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-07 13:14 | ||
|
|
||
|
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 |
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='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 #5 violation: Use |
||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
|
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 #5 violation: Direct dictionary access |
||
| ('name', models.CharField(max_length=255, unique=True)), | ||
| ('description', models.TextField(null=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 #5 violation: Use |
||
| ), | ||
| migrations.CreateModel( | ||
| name='Race', | ||
| 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 #5 violation: Use |
||
| ('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)), | ||
|
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. Direct dictionary access violates checklist item #5. Use |
||
| ], | ||
| ), | ||
|
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 #5 violation: Use |
||
| 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=254)), | ||
| ('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. Checklist item #5 violation: Use |
||
| ('created_at', models.DateTimeField(auto_now_add=True)), | ||
| ('guild', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='players', to='db.guild')), | ||
| ('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='players', 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, related_name='skills', to='db.race')), | ||
| ], | ||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Generated by Django 6.0.5 on 2026-05-07 14:31 | ||
|
|
||
|
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 |
||
| 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(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='players', to='db.guild'), | ||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Generated by Django 6.0.5 on 2026-05-07 14:44 | ||
|
|
||
|
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 import 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 import is unused - line 17 uses |
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('db', '0002_alter_player_guild'), | ||
| ] | ||
|
|
||
| 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'), | ||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Generated by Django 6.0.5 on 2026-05-07 17:37 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('db', '0003_alter_player_guild'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='player', | ||
| name='email', | ||
| field=models.EmailField(max_length=255), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,40 @@ | ||
| from django.db import models | ||
| from django.db.models import ForeignKey | ||
|
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 |
||
|
|
||
|
|
||
| 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" | ||
| ) | ||
|
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. Direct dictionary access |
||
|
|
||
|
|
||
| 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) | ||
|
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. EmailField defaults to max_length=254, but the requirements specify max_length=255. Add explicit max_length=255 to match task requirements. |
||
| email = models.EmailField(max_length=255) | ||
| bio = models.CharField(max_length=255) | ||
| race = models.ForeignKey( | ||
|
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. Direct dictionary access |
||
| Race, | ||
| on_delete=models.CASCADE, | ||
| related_name="players" | ||
| ) | ||
| guild = ForeignKey( | ||
| 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. This violates the task requirement for |
||
| on_delete=models.SET_NULL, | ||
| related_name="players", | ||
| null=True | ||
| ) | ||
| created_at = models.DateTimeField(auto_now_add=True) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,45 @@ | ||
| import json | ||
|
|
||
| import init_django_orm # noqa: F401 | ||
|
|
||
| from db.models import Race, Skill, Player, Guild | ||
|
|
||
|
|
||
| def main() -> None: | ||
| pass | ||
| Race.objects.all().delete() | ||
| Skill.objects.all().delete() | ||
| Player.objects.all().delete() | ||
| Guild.objects.all().delete() | ||
| with open("players.json", "r") as file: | ||
| player_data = json.load(file) | ||
|
|
||
| for player_name, player_info in player_data.items(): | ||
| player_race, _ = Race.objects.get_or_create( | ||
|
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 #5 violation: Use 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 #5: use |
||
| name=player_info["race"].get("name"), | ||
| defaults={"description": player_info["race"].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. Checklist item #5 violation: Use |
||
| player_guild = player_info.get("guild") | ||
| if player_guild: | ||
| player_guild, _ = Guild.objects.get_or_create( | ||
|
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 #5 violation: Use |
||
| name=player_info["guild"].get("name"), | ||
| defaults={"description": player_info["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. Checklist item #5 violation: Direct dictionary access |
||
|
|
||
|
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 #5 violation: Use 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 #5: use |
||
| for skill in player_info["race"]["skills"]: | ||
| Skill.objects.get_or_create( | ||
|
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 #5 violation: Use |
||
| name=skill.get("name"), | ||
| defaults={"bonus": skill.get("bonus"), "race": player_race} | ||
| ) | ||
|
|
||
| Player.objects.create( | ||
| nickname=player_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 #5 violation: Use |
||
| email=player_info.get("email"), | ||
| bio=player_info.get("bio"), | ||
|
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. Uninitialized variable: |
||
| race=player_race, | ||
| guild=player_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.
Unused import:
ForeignKeyis imported fromdjango.db.modelsbut the code usesmodels.ForeignKeyandForeignKeyinconsistently (line 33). Either use the importedForeignKeydirectly or remove the import if not needed.