Spaces:
Sleeping
Sleeping
Download authService/models.py from mohitlahoti2002/djangoServer: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/spaces/mohitlahoti2002/djangoServer/resolve/main/authService/models.py
- Command line
-
hf download hf://spaces/mohitlahoti2002/djangoServer/authService/models.py
-
curl -L -o models.py https://huggingface.co/spaces/mohitlahoti2002/djangoServer/resolve/main/authService/models.py
1.86 kB
| from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin | |
| from django.db import models | |
| from django.utils import timezone | |
| class UserManager(BaseUserManager): | |
| def create_user(self, email, password=None, **extra_fields): | |
| if not email: | |
| raise ValueError('The Email field must be set') | |
| email = self.normalize_email(email) | |
| user = self.model(email=email, **extra_fields) | |
| user.set_password(password) | |
| user.save(using=self._db) | |
| return user | |
| def create_superuser(self, email, password=None, **extra_fields): | |
| extra_fields.setdefault('is_staff', True) | |
| extra_fields.setdefault('is_superuser', True) | |
| if extra_fields.get('is_staff') is not True: | |
| raise ValueError('Superuser must have is_staff=True.') | |
| if extra_fields.get('is_superuser') is not True: | |
| raise ValueError('Superuser must have is_superuser=True.') | |
| return self.create_user(email, password, **extra_fields) | |
| class User(AbstractBaseUser, PermissionsMixin): | |
| ROLE_CHOICES = ( | |
| ('student', 'Student'), | |
| ('teacher', 'Teacher'), | |
| ) | |
| full_name = models.CharField(max_length=255) | |
| email = models.EmailField(unique=True) | |
| phone = models.CharField(max_length=15) | |
| role = models.CharField(max_length=10, choices=ROLE_CHOICES) | |
| is_active = models.BooleanField(default=True) | |
| is_staff = models.BooleanField(default=False) | |
| date_joined = models.DateTimeField(default=timezone.now) | |
| otp = models.CharField(max_length=6, blank=True, null=True) | |
| otp_created_at = models.DateTimeField(blank=True, null=True) | |
| is_verified = models.BooleanField(default=False) | |
| objects = UserManager() | |
| USERNAME_FIELD = 'email' | |
| REQUIRED_FIELDS = ['full_name', 'phone', 'role'] | |
| def __str__(self): | |
| return self.email | |