-
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
Solution #993
Open
CheshireKate
wants to merge
9
commits into
mate-academy:master
Choose a base branch
from
CheshireKate:develop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Solution #993
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e92b792
Solution
CheshireKate e71af58
Solution
CheshireKate a593fe7
Solution
CheshireKate 246cc83
Solution
CheshireKate 9001665
Solution
CheshireKate e77706c
Solution
CheshireKate 7077577
solution
CheshireKate 68a2e03
solution
CheshireKate 07b5ee4
Solution
CheshireKate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Generated by Django 4.0.2 on 2024-09-30 14:42 | ||
|
||
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.TextField(max_length=255)), | ||
('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, 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.CharField(max_length=255, unique=True)), | ||
('bio', models.TextField(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')), | ||
], | ||
), | ||
] |
24 changes: 24 additions & 0 deletions
24
db/migrations/0002_alter_player_email_alter_player_guild.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 4.0.2 on 2024-10-16 15:49 | ||
|
||
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='email', | ||
field=models.EmailField(max_length=255, unique=True), | ||
), | ||
migrations.AlterField( | ||
model_name='player', | ||
name='guild', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='db.guild'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.TextField(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, unique=True) | ||
bio = models.TextField(max_length=255) | ||
race = models.ForeignKey(Race, on_delete=models.CASCADE, related_name="players") | ||
guild = models.ForeignKey(Guild, null=True, on_delete=models.SET_NULL, related_name="players") | ||
created_at = models.DateTimeField(auto_now_add=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,10 +1,45 @@ | ||||||
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: | ||||||
players = json.load(file) | ||||||
for player_name, player_data in players.items(): | ||||||
race_data = player_data["race"] | ||||||
race, created = 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. You could omit the second returned argument since it is not used
Suggested change
|
||||||
name=race_data["name"], | ||||||
defaults={"description": race_data["description"]} | ||||||
) | ||||||
for skill_data in race_data["skills"]: | ||||||
Skill.objects.get_or_create( | ||||||
name=skill_data["name"], | ||||||
defaults={ | ||||||
"bonus": skill_data["bonus"], | ||||||
"race": race | ||||||
} | ||||||
) | ||||||
guild = None | ||||||
if player_data.get("guild"): | ||||||
guild_data = player_data["guild"] | ||||||
guild, created = Guild.objects.get_or_create( | ||||||
name=guild_data["name"], | ||||||
defaults={ | ||||||
"description": guild_data.get("description") | ||||||
} | ||||||
) | ||||||
Player.objects.get_or_create( | ||||||
nickname=player_name, | ||||||
defaults={ | ||||||
"email": player_data["email"], | ||||||
"bio": player_data["bio"], | ||||||
"race": race, | ||||||
"guild": guild, | ||||||
"created_at": "now" | ||||||
} | ||||||
) | ||||||
|
||||||
|
||||||
if __name__ == "__main__": | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ | |
USE_TZ = False | ||
|
||
INSTALLED_APPS = ("db",) | ||
|
||
DEBUG = True |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It is a good practice to include one migration per app per PR in Django projects since it helps to avoid migrations folder overload in the future. Represent all changes done to models in one migration file per app per PR, please