<gh_stars>0
from django.db import models

from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.models import BaseUserManager
from django.conf import settings
#This last import, allows use the setting AUTH_USER_MODEL = 'users_manage_api.UserProfile'


class UserProfileManager(BaseUserManager):
    """Manager for user profile"""

    def create_user(self, email, name, password=None):
        """Create a new user profile"""
        if not email:
            raise ValueError('User must have an email address')

        email = self.normalize_email(email)
        user = self.model(email=email, name=name)

        user.set_password(password)
        user.save(using=self.db)

        return user

    def create_superuser(self, email, name, password):
        """create and save new superuser with given details"""
        user = self.create_user(email, name, password)

        user.is_superuser = True
        user.is_staff = True
        user.is_teacher = True
        user.save(using=self._db)

        return user


class UserProfile(AbstractBaseUser, PermissionsMixin):
    """Database model for users in the system"""

    email = models.EmailField(max_length=255, unique=True)
    #Cannot be two similar emails
    name = models.CharField(max_length=255)
    is_active = models.BooleanField(default=True)
    #if a student stop paying the school, the admin can turn off this attribute
    is_staff = models.BooleanField(default=False)
    #Only the API manager is staff (no teachers, no students, just OscarMCV)
    is_teacher = models.BooleanField(default=False)
    #To make more logic, the model will keep two arguments rather could use only one
    is_student = models.BooleanField(default=True)
    #New feature to manage the users permissions
    objects = UserProfileManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['name']

    def get_full_name(self):
        """Retrieve full name of user"""
        return self.name

    def get_short_name(self):
        """Retrieve short name of user"""
        return self.name

    def __str__(self):
        """return string representation of user"""
        return self.email

from django.db import models

from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.models import BaseUserManager
from django.conf import settings
#This last import, allows use the setting AUTH_USER_MODEL = 'users_manage_api.UserProfile'


class UserProfileManager(BaseUserManager):
    """Manager for user profile"""

    def create_user(self, email, name, password=None):
        """Create a new user profile"""
        if not email:
            raise ValueError('User must have an email address')

        email = self.normalize_email(email)
        user = self.model(email=email, name=name)

        user.set_password(password)
        user.save(using=self.db)

        return user

    def create_superuser(self, email, name, password):
        """create and save new superuser with given details"""
        user = self.create_user(email, name, password)

        user.is_superuser = True
        user.is_staff = True
        user.is_teacher = True
        user.save(using=self._db)

        return user


class UserProfile(AbstractBaseUser, PermissionsMixin):
    """Database model for users in the system"""

    email = models.EmailField(max_length=255, unique=True)
    #Cannot be two similar emails
    name = models.CharField(max_length=255)
    is_active = models.BooleanField(default=True)
    #if a student stop paying the school, the admin can turn off this attribute
    is_staff = models.BooleanField(default=False)
    #Only the API manager is staff (no teachers, no students, just OscarMCV)
    is_teacher = models.BooleanField(default=False)
    #To make more logic, the model will keep two arguments rather could use only one
    is_student = models.BooleanField(default=True)
    #New feature to manage the users permissions
    objects = UserProfileManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['name']

    def get_full_name(self):
        """Retrieve full name of user"""
        return self.name

    def get_short_name(self):
        """Retrieve short name of user"""
        return self.name

    def __str__(self):
        """return string representation of user"""
        return self.email
#This last import, allows use the setting AUTH_USER_MODEL = 'users_manage_api.UserProfile' Manager for user profile Create a new user profile create and save new superuser with given details Database model for users in the system #Cannot be two similar emails #if a student stop paying the school, the admin can turn off this attribute #Only the API manager is staff (no teachers, no students, just OscarMCV) #To make more logic, the model will keep two arguments rather could use only one #New feature to manage the users permissions Retrieve full name of user Retrieve short name of user return string representation of user