Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
- from django.contrib.auth.models import PermissionsMixin
- from django.utils import timezone
- from model_utils.managers import InheritanceManager
- from django.db import models
- from django.utils.translation import ugettext_lazy as _
- class UserManager(BaseUserManager, InheritanceManager):
- def create_user(self, email=None, password=None, **extra_fields):
- now = timezone.now()
- email = self.normalize_email(email)
- u = User(email=email, last_login=now,
- **extra_fields)
- u.set_password(password)
- u.save(using=self._db)
- return u
- def create_superuser(self, email, password, **extra_fields):
- u = self.create_user(email, password, **extra_fields)
- u.is_superuser = True
- u.is_admin = True
- u.is_staff = True
- u.save(using=self._db)
- return u
- def user_directory_path(instance, filename):
- # file will be uploaded to MEDIA_ROOT/username/<filename>
- return 'user_{0}/{1}'.format(instance.username, filename)
- class User(AbstractBaseUser, PermissionsMixin):
- def get_full_name(self):
- return str(self.username)
- def get_short_name(self):
- return str(self.username)
- email = models.EmailField(unique=True)
- objects = UserManager()
- account_choices = (
- ('PRO', 'Provider'),
- ('CON', 'Consumer'),
- )
- account_type = models.CharField(max_length=3, choices=account_choices)
- image = models.ImageField(upload_to=user_directory_path, height_field=None, width_field=None, max_length=100,
- null=True,
- blank=True)
- address = models.CharField(max_length=100)
- description = models.TextField(max_length=1000, blank=True)
- city = models.CharField(max_length=200)
- phone_number = models.CharField(max_length=200)
- website = models.URLField(blank=True, null=True)
- username = models.CharField(_('Username'), blank=True, max_length=50)
- is_active = models.BooleanField(_('Active'), default=True)
- groups = models.ManyToManyField(blank=True,
- help_text='The groups this hospital belongs to. '
- 'An hospital will get all permissions granted to '
- 'each of their groups.', related_name='hospital_set',
- related_query_name='hospital', to='auth.Group', verbose_name='groups')
- is_logged_in = models.BooleanField(_('Logged In'), default=False)
- has_configured_account = models.BooleanField(_('Has Configured Account'), default=False)
- first_name = models.CharField(_('First Name'), max_length=200, blank=True)
- last_name = models.CharField(_('Last Name'), max_length=200, blank=True)
- bank_account_name = models.CharField(_('Bank Account Name'), max_length=400, blank=True)
- bank_name = models.CharField(_('Bank Name'), max_length=500, blank=True)
- bank_account_number = models.CharField(_('Account Number'), max_length=30, blank=True)
- def __unicode__(self):
- return self.username
- USERNAME_FIELD = 'email'
- REQUIRED_FIELD = ['account_type']
- @property
- def image_url(self):
- if self.image and hasattr(self.image, 'url'):
- return self.image.url
- class Worker(models.Model):
- user = models.ForeignKey(User, on_delete=models.CASCADE)
- is_superuser = models.BooleanField(_('Superuser'), default=False)
- is_admin = models.BooleanField(_('Admin'), default=False)
- is_staff = models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.',
- verbose_name='staff status')
- class Admin(models.Model):
- user = models.ForeignKey(User, on_delete=models.CASCADE)
- is_superuser = models.BooleanField(_('Superuser'), default=False)
- is_admin = models.BooleanField(_('Admin'), default=False)
- is_staff = models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.',
- verbose_name='staff status')
- class NormalUser(models.Model):
- user = models.ForeignKey(User, on_delete=models.CASCADE)
- is_superuser = models.BooleanField(_('Superuser'), default=False)
- is_admin = models.BooleanField(_('Admin'), default=False)
- is_staff = models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.',
- verbose_name='staff status')
- class Attendance(models.Model):
- user = models.ForeignKey(NormalUser, on_delete=models.CASCADE)
- datetime = models.DateTimeField(default=timezone.now)
- presence = models.BooleanField(default=False)
- entry_time = models.TimeField(default=timezone.now)
- exit_time = models.TimeField(default=timezone.now)
Add Comment
Please, Sign In to add comment