2022-10-07 22:15:12 +03:00
|
|
|
from django.contrib.auth.models import AbstractUser
|
2022-10-08 13:52:49 +03:00
|
|
|
from django.core.validators import MinValueValidator
|
2022-10-07 22:15:12 +03:00
|
|
|
from django.db import models
|
|
|
|
|
2022-10-08 19:57:46 +03:00
|
|
|
from faker import Faker
|
|
|
|
|
2022-10-07 22:15:12 +03:00
|
|
|
|
|
|
|
class User(AbstractUser):
|
2022-10-08 00:48:53 +03:00
|
|
|
class WorkerType(models.TextChoices):
|
|
|
|
WORKER = "WORKER", "worker"
|
|
|
|
HR = "HR", "human resources"
|
|
|
|
ADMIN = "ADMIN", "administrator"
|
2022-10-07 22:15:12 +03:00
|
|
|
|
|
|
|
first_name = None
|
|
|
|
last_name = None
|
|
|
|
|
|
|
|
# image = models.ImageField(upload_to=user_file_upload_mixin, blank=True)
|
|
|
|
# image_cropped = models.ImageField(upload_to="cropped/", blank=True)
|
|
|
|
|
|
|
|
about = models.TextField(blank=True)
|
2022-10-08 16:02:57 +03:00
|
|
|
name = models.CharField(max_length=120)
|
2022-10-08 00:48:53 +03:00
|
|
|
type = models.CharField(
|
|
|
|
max_length=6, choices=WorkerType.choices, default=WorkerType.WORKER
|
|
|
|
)
|
2022-10-08 19:57:46 +03:00
|
|
|
clan = models.ForeignKey("users.Clan", on_delete=models.SET_NULL, null=True)
|
2022-10-08 16:02:57 +03:00
|
|
|
command = models.ForeignKey(
|
|
|
|
"users.Command", related_name="workers", on_delete=models.CASCADE
|
|
|
|
)
|
2022-10-08 13:52:49 +03:00
|
|
|
salary = models.IntegerField(default=0, validators=[MinValueValidator(0)])
|
|
|
|
respect = models.IntegerField(default=0, validators=[MinValueValidator(0)])
|
2022-10-08 16:02:57 +03:00
|
|
|
wallet_private_key = models.CharField(max_length=96, unique=True)
|
|
|
|
wallet_public_key = models.CharField(max_length=96, unique=True)
|
|
|
|
telegram = models.CharField(max_length=100, unique=True)
|
2022-10-07 22:15:12 +03:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.username
|
|
|
|
|
2022-10-08 00:48:53 +03:00
|
|
|
@property
|
2022-10-08 11:21:53 +03:00
|
|
|
def is_manager(self):
|
2022-10-08 00:48:53 +03:00
|
|
|
return self.type in [self.WorkerType.HR, self.WorkerType.ADMIN]
|
|
|
|
|
2022-10-08 11:21:53 +03:00
|
|
|
@property
|
|
|
|
def is_admin(self):
|
|
|
|
return self.type == self.WorkerType.ADMIN
|
|
|
|
|
2022-10-08 16:02:57 +03:00
|
|
|
@property
|
|
|
|
def department(self):
|
|
|
|
return self.command.stream.department.name
|
|
|
|
|
2022-10-07 22:15:12 +03:00
|
|
|
class Meta:
|
2022-10-08 16:02:57 +03:00
|
|
|
ordering = ["-id"]
|
|
|
|
|
|
|
|
|
|
|
|
class Department(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class Stream(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
department = models.ForeignKey(
|
|
|
|
Department, related_name="streams", on_delete=models.CASCADE
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class Command(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
stream = models.ForeignKey(
|
|
|
|
Stream, related_name="commands", on_delete=models.CASCADE
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2022-10-08 19:57:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Clan(models.Model):
|
|
|
|
name = models.CharField(max_length=100, null=True)
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
name = Faker().name()
|
|
|
|
self.name = name + "'s clan"
|
|
|
|
super(Clan, self).save(*args, **kwargs)
|