backend/app/users/models.py

40 lines
1.1 KiB
Python
Raw Normal View History

2022-10-07 22:15:12 +03:00
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
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)
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
def save(self, *args, **kwargs):
self.set_password(self.password)
super(AbstractUser, self).save(*args, **kwargs)
@property
def is_manager(self):
return self.type in [self.WorkerType.HR, self.WorkerType.ADMIN]
@property
def is_admin(self):
return self.type == self.WorkerType.ADMIN
2022-10-07 22:15:12 +03:00
class Meta:
ordering = ["-id"]