mode.py

mail@pastecode.io avatar
unknown
python
2 years ago
2.2 kB
2
Indexable
Never
from django.contrib.auth.models import AbstractUser
from django.db import models
from .managers import CustomUserManager

IS_CHECK = (
    ('Y', "Yes"),
    ('N', "No"),
)

GENDER = [
    ('Male', 'Male'),
    ('Female', 'Female')
]


class User(AbstractUser):
    username = None
    email = models.EmailField(
        unique=True, blank=False,
        error_messages={
            'unique': "A user with that email already exists.",
        }
    )
    # role = models.CharField(choices=Group, max_length=10)
    is_active = models.BooleanField(default=True)
    is_check = models.BooleanField(default=False)

    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = []

    def __str__(self):
        return self.email

    def get_full_name(self):
        return self.first_name + ' ' + self.last_name

    objects = CustomUserManager()


class UserCompany(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    email = models.EmailField()
    phone = models.CharField(max_length=14)
    gender = models.CharField(choices=GENDER, default='Others', max_length=20)
    profile_picture = models.ImageField(upload_to='dp/', blank=True, null=True, default='dp.png')
    companny_branch = models.ForeignKey('UserCompanyBranch', on_delete=models.CASCADE, blank=True, null=True)

    class Meta:
        verbose_name_plural = 'Companies'

    def __str__(self):
        return self.first_name + self.last_name


# class CompanyGroup(models.Model):
#     user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
#     company_name = models.CharField(max_length=50)
#     company = models.ForeignKey(UserCompany, on_delete=models.CASCADE, null=True, blank=True)
#
#     class Meta:
#         verbose_name_plural = 'Company Group'
#
#     def __str__(self):
#         return self.company_name


class UserCompanyBranch(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
    branch_name = models.CharField(max_length=50)

    class Meta:
        verbose_name_plural = 'Company Branches'

    def __str__(self):
        return self.branch_name