mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-22 23:17:09 +00:00
add achievements field to user model
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
from http import HTTPStatus as status
|
||||
|
||||
from ninja import Router
|
||||
|
||||
from apps.achievement.models import Achievement
|
||||
from api.v1.achievement.schemas import AchievementSchema
|
||||
from api.v1.schemas import UnauthorizedError
|
||||
|
||||
router = Router()
|
||||
|
||||
|
||||
@router.get(
|
||||
"",
|
||||
response={
|
||||
status.OK: list[AchievementSchema],
|
||||
status.UNAUTHORIZED: UnauthorizedError,
|
||||
}
|
||||
)
|
||||
def get_all_achievements(request):
|
||||
return Achievement.objects.all()
|
||||
@@ -22,4 +22,4 @@ class LoginSchema(ModelSchema):
|
||||
class UserSchema(ModelSchema):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ["id", "email", "username", "created_at",]
|
||||
fields = ["id", "email", "username", "created_at", "achievements"]
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.1.6 on 2025-03-02 12:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('achievement', '0001_initial'),
|
||||
('user', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='achievements',
|
||||
field=models.ManyToManyField(blank=True, to='achievement.achievement', verbose_name='ачивки пользователя'),
|
||||
),
|
||||
]
|
||||
@@ -1,6 +1,7 @@
|
||||
from django.contrib.auth.hashers import check_password, make_password
|
||||
from django.db import models
|
||||
|
||||
from apps.achievement.models import Achievement
|
||||
from apps.core.models import BaseModel
|
||||
|
||||
|
||||
@@ -16,6 +17,9 @@ class User(BaseModel):
|
||||
|
||||
created_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
achievements = models.ManyToManyField(Achievement, blank=True,
|
||||
verbose_name="ачивки пользователя")
|
||||
|
||||
@staticmethod
|
||||
def make_password(password: str):
|
||||
return make_password(password)
|
||||
|
||||
Reference in New Issue
Block a user