Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- from guardian.mixins import GuardianUserMixin
- from django.contrib.auth.models import AbstractUser, UserManager, send_mail
- from django.utils import timezone
- class GeneralUser(AbstractUser, GuardianUserMixin):
- username = models.CharField(
- ('username'),
- max_length=150,
- unique=True,
- help_text=('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'),
- error_messages={
- 'unique': ("A user with that username already exists."),
- },
- )
- password = models.CharField(max_length=100)
- email = models.EmailField(('email address'), blank=True)
- is_active = models.BooleanField(
- ('active'),
- default=True,
- help_text=(
- 'Designates whether this user should be treated as active. '
- 'Unselect this instead of deleting accounts.'
- ),
- )
- objects = UserManager()
- date_joined = models.DateTimeField(('date joined'), default=timezone.now)
- business_name = models.CharField(('business name'), max_length=150, blank=True)
- USERNAME_FIELD = 'username'
- def email_user(self, subject, message, from_email=None, **kwargs):
- """
- Sends an email to this User.
- """
- send_mail(subject, message, from_email, [self.email], **kwargs)
- def get_custom_anon_user(User):
- return User(
- username='AnonymousUser',
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement