-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Implement game database #1727
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?
Implement game database #1727
Changes from 1 commit
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.4 on 2026-05-16 10:20 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| ] | ||
|
|
||
|
bijirin marked this conversation as resolved.
|
||
| operations = [ | ||
|
bijirin marked this conversation as resolved.
|
||
| 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)), | ||
|
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 requires using |
||
| ('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 requires using |
||
| ], | ||
| ), | ||
| migrations.CreateModel( | ||
|
bijirin marked this conversation as resolved.
|
||
| name='Race', | ||
|
bijirin marked this conversation as resolved.
|
||
| 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)), | ||
|
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 requires 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. Checklist item #5 requires using |
||
| ), | ||
| migrations.CreateModel( | ||
| name='Player', | ||
| 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 requires using |
||
| ('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. Checklist item #5 requires using |
||
| ('email', models.EmailField(max_length=254)), | ||
| ('bio', models.CharField(max_length=255)), | ||
| ('created_at', models.DateTimeField(auto_now_add=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.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, to='db.race')), | ||
| ], | ||
| ), | ||
| ] | ||
| 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.CharField(max_length=255) | ||
| race = models.ForeignKey(Race, on_delete=models.CASCADE) | ||
|
bijirin marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| 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(unique=False) | ||
| bio = models.CharField(max_length=255) | ||
| race = models.ForeignKey(Race, on_delete=models.CASCADE) | ||
|
bijirin marked this conversation as resolved.
Outdated
|
||
| guild = models.ForeignKey(Guild, on_delete=models.SET_NULL, null=True) | ||
|
bijirin marked this conversation as resolved.
Outdated
|
||
| created_at = models.DateTimeField(auto_now_add=True) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,42 @@ | ||
| 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 key, value in players.items(): | ||
|
|
||
|
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 #3: ForeignKey fields must have |
||
| player_race, created = Race.objects.get_or_create( | ||
| name=value["race"]["name"], | ||
| description=value["race"]["description"], | ||
| ) | ||
|
|
||
| for skill in value["race"]["skills"]: | ||
| Skill.objects.get_or_create( | ||
| name=skill["name"], | ||
| bonus=skill["bonus"], | ||
| race=player_race, | ||
| ) | ||
|
|
||
|
bijirin marked this conversation as resolved.
|
||
| if value["guild"] is None: | ||
|
bijirin marked this conversation as resolved.
|
||
| player_guild = None | ||
| else: | ||
| player_guild, created = Guild.objects.get_or_create( | ||
| name=value["guild"]["name"], | ||
| description=value["guild"]["description"], | ||
| ) | ||
|
|
||
| Player.objects.get_or_create( | ||
| nickname=key, | ||
| email=value["email"], | ||
| bio=value["bio"], | ||
| race=player_race, | ||
| guild=player_guild, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.