Skip to content

Commit

Permalink
Migrations and fix the prefix on the core model
Browse files Browse the repository at this point in the history
  • Loading branch information
joshSzep committed Jul 8, 2024
1 parent f4df77b commit 6e1be97
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
65 changes: 65 additions & 0 deletions challenges/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Generated by Django 5.0.6 on 2024-07-08 13:22

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Challenge',
fields=[
('id', models.CharField(editable=False, max_length=42, primary_key=True, serialize=False, unique=True)),
('active', models.BooleanField(default=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('name', models.CharField(max_length=100)),
('description', models.TextField()),
('time_limit', models.IntegerField()),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Sentence',
fields=[
('id', models.CharField(editable=False, max_length=42, primary_key=True, serialize=False, unique=True)),
('active', models.BooleanField(default=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('hangul', models.TextField()),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='ChallengeResult',
fields=[
('id', models.CharField(editable=False, max_length=42, primary_key=True, serialize=False, unique=True)),
('active', models.BooleanField(default=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('speed', models.IntegerField(default=0)),
('challenge', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='challenges.challenge')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='challenge',
name='sentences',
field=models.ManyToManyField(to='challenges.sentence'),
),
]
4 changes: 2 additions & 2 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class CoreBaseModel(models.Model):
id = models.CharField(
max_length=41, # 36 characters for UUID + 5 characters for prefix
max_length=42, # 36 characters for UUID + 5 characters for prefix + 1 just cuz
primary_key=True,
editable=False,
unique=True,
Expand All @@ -21,7 +21,7 @@ class Meta:
@classmethod
def get_prefix(cls):
name = re.sub(r"(?<!^)(?=[A-Z])", "_", cls.__name__).lower()
return name[:4] + "|"
return name[:4]

def save(self, *args, **kwargs):
if not self.id:
Expand Down

0 comments on commit 6e1be97

Please sign in to comment.