mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-06-10 04:32:34 +00:00
feat: added achievements
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 182 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 193 KiB |
@@ -0,0 +1,32 @@
|
||||
from django.conf import settings
|
||||
from django.core.files import File
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
from apps.achievement.models import Achievement
|
||||
|
||||
icons_dir = f"{settings.BASE_DIR}/apps/achievement/icons"
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Create achievement fixtures."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if not Achievement.objects.filter(slug="first_steps").exists():
|
||||
with open(f"{icons_dir}/first_steps.png", "rb") as f:
|
||||
first_steps_icon = File(f, name="first_steps.png")
|
||||
Achievement.objects.get_or_create(
|
||||
name="Первые шаги",
|
||||
description="Отправьте свое первое решение на задачу!",
|
||||
slug="first_steps",
|
||||
icon=first_steps_icon,
|
||||
)
|
||||
|
||||
if not Achievement.objects.filter(slug="welcome").exists():
|
||||
with open(f"{icons_dir}/welcome.png", "rb") as f:
|
||||
welcome_icon = File(f, name="welcome.png")
|
||||
Achievement.objects.get_or_create(
|
||||
name="Добро пожаловать!",
|
||||
description="Зарегистрируйтесь на платформе",
|
||||
slug="welcome",
|
||||
icon=welcome_icon,
|
||||
)
|
||||
@@ -1,6 +1,7 @@
|
||||
# Generated by Django 5.1.6 on 2025-03-02 21:24
|
||||
# Generated by Django 5.1.6 on 2025-03-02 22:53
|
||||
|
||||
import apps.achievement.models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
from django.db import migrations, models
|
||||
|
||||
@@ -27,4 +28,15 @@ class Migration(migrations.Migration):
|
||||
'verbose_name_plural': 'ачивки',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='UserAchievement',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('received_at', models.DateTimeField(auto_now_add=True)),
|
||||
('achievement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='achievement.achievement')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 5.1.6 on 2025-03-02 22:53
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('achievement', '0001_initial'),
|
||||
('user', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='userachievement',
|
||||
name='user',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='user.user'),
|
||||
),
|
||||
]
|
||||
@@ -4,9 +4,6 @@ from apps.core.models import BaseModel
|
||||
|
||||
|
||||
class Achievement(BaseModel):
|
||||
class AchievementType(models.TextChoices):
|
||||
CORRECT_TASKS = "correct_tasks", "Выполненные задания"
|
||||
|
||||
def image_url_upload_to(instance, filename):
|
||||
return f"achievements/{instance.id}/icon/{filename}"
|
||||
|
||||
@@ -27,3 +24,10 @@ class Achievement(BaseModel):
|
||||
class Meta:
|
||||
verbose_name = "ачивка"
|
||||
verbose_name_plural = "ачивки"
|
||||
|
||||
|
||||
class UserAchievement(BaseModel):
|
||||
achievement = models.ForeignKey(Achievement, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey("user.User", on_delete=models.CASCADE)
|
||||
|
||||
received_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
Reference in New Issue
Block a user