Skip to content

Commit

Permalink
feat: Add slug field to Game
Browse files Browse the repository at this point in the history
  • Loading branch information
barnslig committed Dec 25, 2021
1 parent b8a5c3f commit cdc0c86
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
30 changes: 30 additions & 0 deletions backend/dpt_app/trails/migrations/0017_add_game_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.2.9 on 2021-12-25 16:23

from django.db import migrations, models
from django.utils.text import slugify
import django.utils.timezone


def add_slug(apps, schema_editor):
Game = apps.get_model("trails", "Game")

for game in Game.objects.all():
game.slug = slugify(game.name)
game.save()


class Migration(migrations.Migration):

dependencies = [
('trails', '0016_migrate_enums_20211224_2220'),
]

operations = [
migrations.AddField(
model_name='game',
name='slug',
field=models.SlugField(default=django.utils.timezone.now),
preserve_default=False,
),
migrations.RunPython(add_slug),
]
2 changes: 2 additions & 0 deletions backend/dpt_app/trails/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Meta:
verbose_name=pgettext_lazy("Game Name", "Name")
)

slug = models.SlugField()

clock_state = models.CharField(
max_length=255,
choices=ClockType.choices,
Expand Down
4 changes: 2 additions & 2 deletions backend/dpt_app/trails/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def buildJsonResponse(data):

def get_game_or_404(func):
def inner(request, gameId, *args, **kwargs):
try:
game = Game.objects.get(name=gameId)
try:
game = Game.objects.get(slug=gameId)
except Game.DoesNotExist:
return JsonResponse({"Errors": [
{
Expand Down

0 comments on commit cdc0c86

Please sign in to comment.