<reponame>QUDUSKUNLE/OPEN-API
from django.db import models
from django.contrib.auth.models import AbstractUser, BaseUserManager


class UserManager(BaseUserManager):
    use_in_migrations = True

    def _create_user(self, **fields):
        """
        Create and save a user with the given username, email, and password.
        """
        email = fields.pop('email')
        password = fields.get('password')
        bio = fields.get('bio')
        name = fields.get('name')
        if not email:
            raise ValueError("Email address is required")
        elif not bio:
            raise ValueError("Bio is required")
        elif not name:
            raise ValueError('Name is required')
        email = self.normalize_email(email)
        user = self.model(email=email, **fields)
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_user(self, **fields):
        fields.setdefault('is_staff', False)
        fields.setdefault('is_superuser', False)

        return self._create_user(**fields)

    def create_superuser(self, **fields):
        fields.setdefault('is_staff', True)
        fields.setdefault('is_superuser', True)

        if fields.get('is_staff') is not True:
            raise ValueError('Superuser must have is_staff=True.')
        if fields.get('is_superuser') is not True:
            raise ValueError('Superuser must have is_superuser=True.')

        return self._create_user(**fields)


class User(AbstractUser):
    email = models.EmailField(max_length=50, unique=True)
    bio = models.TextField(max_length=500, blank=True)
    name = models.CharField(max_length=255)
    last_modified = models.DateTimeField(auto_now=True, editable=False)
    password = models.CharField(max_length=128, blank=True, null=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['bio', 'name']
    objects = UserManager()

    class Meta:
        verbose_name_plural = "Users"
        ordering = ['-id']

from django.db import models
from django.contrib.auth.models import AbstractUser, BaseUserManager


class UserManager(BaseUserManager):
    use_in_migrations = True

    def _create_user(self, **fields):
        """
        Create and save a user with the given username, email, and password.
        """
        email = fields.pop('email')
        password = fields.get('password')
        bio = fields.get('bio')
        name = fields.get('name')
        if not email:
            raise ValueError("Email address is required")
        elif not bio:
            raise ValueError("Bio is required")
        elif not name:
            raise ValueError('Name is required')
        email = self.normalize_email(email)
        user = self.model(email=email, **fields)
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_user(self, **fields):
        fields.setdefault('is_staff', False)
        fields.setdefault('is_superuser', False)

        return self._create_user(**fields)

    def create_superuser(self, **fields):
        fields.setdefault('is_staff', True)
        fields.setdefault('is_superuser', True)

        if fields.get('is_staff') is not True:
            raise ValueError('Superuser must have is_staff=True.')
        if fields.get('is_superuser') is not True:
            raise ValueError('Superuser must have is_superuser=True.')

        return self._create_user(**fields)


class User(AbstractUser):
    email = models.EmailField(max_length=50, unique=True)
    bio = models.TextField(max_length=500, blank=True)
    name = models.CharField(max_length=255)
    last_modified = models.DateTimeField(auto_now=True, editable=False)
    password = models.CharField(max_length=128, blank=True, null=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['bio', 'name']
    objects = UserManager()

    class Meta:
        verbose_name_plural = "Users"
        ordering = ['-id']
Create and save a user with the given username, email, and password.