Spaces:
Sleeping
Sleeping
| from django.db import models | |
| # Create your models here. | |
| from django.db import models | |
| from django.contrib.auth.models import BaseUserManager, AbstractBaseUser | |
| DEFAULT_PROFILE_IMAGE_LINK = 'https://firebasestorage.googleapis.com/v0/b/deaf-traductor.appspot.com/o/profile_deaf.png?alt=media&token=d03df52d-7191-43a6-b6d2-1d6fc66c6845' | |
| class UserManager(BaseUserManager): | |
| def create_user(self,email, password): | |
| """ | |
| Creates and saves a User with the given email and password. | |
| """ | |
| if not email: | |
| raise ValueError('Users must have email address') | |
| user = self.model( | |
| email=self.normalize_email(email), | |
| ) | |
| user.set_password(password) | |
| user.save(using=self._db) | |
| return user | |
| def create_staffuser(self, email, password): | |
| """user | |
| Creates and saves a staff user with the given email and password. | |
| """ | |
| user = self.create_user( | |
| email = email, | |
| password=password, | |
| ) | |
| user.staff = True | |
| user.save(using=self._db) | |
| return user | |
| def create_superuser(self, email, password): | |
| """ | |
| Creates and saves a superuser with the given email and password. | |
| """ | |
| user = self.create_user( | |
| email = email, | |
| password=password, | |
| ) | |
| user.staff = True | |
| user.admin = True | |
| user.is_active = True | |
| user.save(using=self._db) | |
| return user | |
| class User(AbstractBaseUser): | |
| email = models.EmailField(max_length=255, unique=True) | |
| first_name = models.CharField(max_length=255, null=True) | |
| last_name = models.CharField(max_length=255, null=True) | |
| image = models.FileField(max_length=250, null=True) | |
| is_active = models.BooleanField(default=True) | |
| staff = models.BooleanField(default=False) | |
| objects = UserManager() | |
| USERNAME_FIELD = 'email' | |
| def get_full_name(self): | |
| return f"{self.email}" | |
| def get_short_name(self): | |
| return self.email | |
| def __str__(self): | |
| return self.email | |
| def has_perm(self, perm, obj=None): | |
| "Does the user have a specific permission?" | |
| # Simplest possible answer: Yes, always | |
| return True | |
| def has_module_perms(self, app_label): | |
| "Does the user have permissions to view the app `app_label`?" | |
| # Simplest possible answer: Yes, always | |
| return True | |
| def is_staff(self): | |
| "Is the user a member of staff?" | |
| return self.staff | |
| def is_admin(self): | |
| "Is the user a admin member?" | |
| return self.admin | |
| class UserActivationCode(models.Model): | |
| user = models.ForeignKey(User, on_delete=models.CASCADE, null=True) | |
| activation_code = models.CharField(max_length=20, null=True) | |
| usable = models.BooleanField(default=True) | |
| def __str__(self) -> str: | |
| return self.user.email + " : " + self.activation_code | |