Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

users/models.py

View models.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.core.urlresolvers import reverse
 
from .managers import UserManager
 
class User(AbstractBaseUser):
email = models.EmailField(max_length=255, unique=True)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now_add=True)
objects = UserManager()
 
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name']
 
def get_full_name(self):
return '%s %s' % (self.first_name, self.last_name)
 
def get_short_name(self):
return self.email
 
def __unicode__(self):
return self.email
 
def has_perm(self, perm, obj=None):
return True
 
def has_module_perms(self, app_label):
return True
 
@property
def is_staff(self):
return self.is_admin
 
@property
def is_employed(self):
return self.position != None
 
@property
def company(self):
if self.is_employed:
return self.position.company
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.