2022-10-07 22:15:12 +03:00
|
|
|
from django.contrib.auth.models import AbstractUser
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
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 00:48:53 +03:00
|
|
|
type = models.CharField(
|
|
|
|
max_length=6, choices=WorkerType.choices, default=WorkerType.WORKER
|
|
|
|
)
|
|
|
|
salary = models.IntegerField(default=0)
|
2022-10-07 22:15:12 +03:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.username
|
|
|
|
|
2022-10-08 00:48:53 +03:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
self.set_password(self.password)
|
|
|
|
super(AbstractUser, self).save(*args, **kwargs)
|
|
|
|
|
|
|
|
@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-07 22:15:12 +03:00
|
|
|
class Meta:
|
|
|
|
ordering = ["-id"]
|