-
Notifications
You must be signed in to change notification settings - Fork 917
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
Develop #1009
base: master
Are you sure you want to change the base?
Develop #1009
Changes from 2 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 4.0.2 on 2024-10-27 12:24 | ||
|
||
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)), | ||
('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)), | ||
('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='skills', to='db.race')), | ||
], | ||
), | ||
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, related_name='players', to='db.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. The 'to' parameter in the ForeignKey should be 'Guild' instead of 'db.guild'. Ensure that the app label is correctly referenced if it's not the default app. |
||
('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='players', to='db.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. The 'to' parameter in the ForeignKey should be 'Race' instead of 'db.race'. Ensure that the app label is correctly referenced if it's not the default app. |
||
], | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.0.2 on 2024-10-28 05:37 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
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.SET_NULL, related_name='players', to='db.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. The 'to' parameter in the ForeignKey should be 'Guild' instead of 'db.guild'. Ensure that the app label is correctly referenced if it's not the default app. |
||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.0.2 on 2024-10-28 05:46 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('db', '0002_alter_player_guild'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='skill', | ||
name='race', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='skill_set', to='db.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. The 'to' parameter in the ForeignKey should be 'Race' instead of 'db.race'. Ensure that the app label is correctly referenced if it's not the default app. |
||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,39 @@ | ||
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="skill_set" | ||
) | ||
|
||
|
||
class Guild(models.Model): | ||
name = models.CharField(max_length=255) | ||
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,51 @@ | ||
import os.path | ||
import json | ||
|
||
import init_django_orm # noqa: F401 | ||
|
||
from db.models import Race, Skill, Player, Guild | ||
|
||
|
||
def main() -> None: | ||
pass | ||
directory = os.path.join("db", "tests", "players.json") | ||
|
||
with open(directory, "r") as data_players: | ||
players = json.load(data_players) | ||
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. Also you can just write: |
||
|
||
for nickname, player_data in players.items(): | ||
email = player_data.get("email") | ||
bio = player_data.get("bio") | ||
|
||
race_name = player_data.get("race").get("name") | ||
race_description = player_data.get("race").get("description") | ||
race_skills = player_data.get("race").get("skills") | ||
|
||
race, _ = Race.objects.get_or_create( | ||
name=race_name, | ||
description=race_description | ||
) | ||
for skill in race_skills: | ||
Skill.objects.get_or_create( | ||
name=skill.get("name"), | ||
bonus=skill.get("bonus"), | ||
race=race | ||
) | ||
|
||
guild = player_data.get("guild") | ||
|
||
if guild: | ||
guild, _ = Guild.objects.get_or_create( | ||
name=guild.get("name"), | ||
description=guild.get("description") | ||
) | ||
|
||
Player.objects.create( | ||
nickname=nickname, | ||
email=email, | ||
bio=bio, | ||
race=race, | ||
guild=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. There is a potential issue here: if 'guild' is not present in the player data, the 'guild' variable will be undefined when passed to Player.objects.create. Consider initializing 'guild' to None before the if statement to avoid this issue. |
||
) | ||
|
||
|
||
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.
The 'to' parameter in the ForeignKey should be 'Race' instead of 'db.race'. Ensure that the app label is correctly referenced if it's not the default app.