mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-19 14:04:07 +01:00
Merge branch 'main' into feature/calendar
This commit is contained in:
commit
1f494aac1f
@ -4,3 +4,6 @@ from django.apps import AppConfig
|
|||||||
class UsersConfig(AppConfig):
|
class UsersConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'users'
|
name = 'users'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
import users.signals
|
||||||
30
backend/users/migrations/0004_userstats.py
Normal file
30
backend/users/migrations/0004_userstats.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Generated by Django 4.2.6 on 2023-11-06 05:30
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0003_customuser_profile_pic'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='UserStats',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('health', models.IntegerField(default=100)),
|
||||||
|
('gold', models.FloatField(default=0.0)),
|
||||||
|
('experience', models.FloatField(default=0)),
|
||||||
|
('strength', models.IntegerField(default=1)),
|
||||||
|
('intelligence', models.IntegerField(default=1)),
|
||||||
|
('endurance', models.IntegerField(default=1)),
|
||||||
|
('perception', models.IntegerField(default=1)),
|
||||||
|
('luck', models.IntegerField(default=1)),
|
||||||
|
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -1,7 +1,11 @@
|
|||||||
|
import random
|
||||||
|
import math
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
|
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
|
||||||
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
|
|
||||||
from .managers import CustomAccountManager
|
from .managers import CustomAccountManager
|
||||||
|
|
||||||
@ -32,15 +36,33 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
|||||||
return self.username
|
return self.username
|
||||||
|
|
||||||
|
|
||||||
# class UserStats(models.Model):
|
def random_luck():
|
||||||
# """
|
return random.randint(1, 50)
|
||||||
# Represents User Profiles and Attributes.
|
|
||||||
# Fields:
|
class UserStats(models.Model):
|
||||||
# - health: health points of the user.
|
"""
|
||||||
# - gold: gold points of the user.
|
Represents User Profiles and Attributes.
|
||||||
# - experience: experience points of the user.
|
Fields:
|
||||||
# """
|
- health: health points of the user.
|
||||||
# user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
|
- gold: gold points of the user.
|
||||||
# health = models.IntegerField(default=100)
|
- experience: experience points of the user.
|
||||||
# gold = models.IntegerField(default=0)
|
"""
|
||||||
# experience = models.FloatField(default=0)
|
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
|
||||||
|
health = models.IntegerField(default=100)
|
||||||
|
gold = models.FloatField(default=0.0)
|
||||||
|
experience = models.FloatField(default=0)
|
||||||
|
strength = models.IntegerField(default=1,
|
||||||
|
validators=[MinValueValidator(1),
|
||||||
|
MaxValueValidator(100)])
|
||||||
|
intelligence = models.IntegerField(default=1, validators=[MinValueValidator(1),
|
||||||
|
MaxValueValidator(100)])
|
||||||
|
endurance = models.IntegerField(default=1, validators=[MinValueValidator(1),
|
||||||
|
MaxValueValidator(100)])
|
||||||
|
perception = models.IntegerField(default=1, validators=[MinValueValidator(1),
|
||||||
|
MaxValueValidator(100)])
|
||||||
|
luck = models.IntegerField(default=random_luck, validators=[MinValueValidator(1),
|
||||||
|
MaxValueValidator(50)],)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def level(self):
|
||||||
|
return (math.pow(self.experience, 2) // 225) + 1
|
||||||
9
backend/users/signals.py
Normal file
9
backend/users/signals.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from django.db.models.signals import post_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
from users.models import CustomUser, UserStats
|
||||||
|
|
||||||
|
@receiver(post_save, sender=CustomUser)
|
||||||
|
def create_user_stats(sender, instance, created, **kwargs):
|
||||||
|
if created:
|
||||||
|
UserStats.objects.create(user=instance)
|
||||||
Loading…
Reference in New Issue
Block a user