Skip to content

Instantly share code, notes, and snippets.

@meoooh
Created December 11, 2013 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meoooh/7905859 to your computer and use it in GitHub Desktop.
Save meoooh/7905859 to your computer and use it in GitHub Desktop.
class MyUserManager(BaseUserManager):
def create(self, email, name, birthday, sex, password):
return self.create_user(email=email,
password=password,
name=name,
birthday=birthday,
sex=sex,
)
def create_user(self, email, name, birthday, sex, password):
if not email:
raise ValueError(_('email cannot be blank.'))
user = self.model(
email=MyUserManager.normalize_email(email),
name=name,
birthday=birthday,
sex=sex,
is_active=True,
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, name, birthday, sex, password):
user = self.create_user(email=email,
password=password,
name=name,
birthday=birthday,
sex=sex,
)
user.is_staff=True
user.is_superuser=True
user.is_admin=True
user.save(using=self._db)
return user
class VomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=254, unique=True, db_index=True)
name = models.CharField(max_length=254)
birthday = models.DateField()
sex = models.SmallIntegerField()
dateOfRecevingLastQuestion = models.DateField(
default=date.today()-timedelta(days=1)
)
questionOfToday = models.ForeignKey(Question, null=True, blank=True)
constellation = models.ForeignKey(Constellation, null=True, blank=True)
switch = models.BooleanField(default=False)
creation = models.DateTimeField(auto_now_add=True)
modification = models.DateTimeField(auto_now=True)
objects = MyUserManager()
is_staff = models.BooleanField(default=False, blank=True,)
is_active = models.BooleanField(default=True, blank=True,)
def __unicode__(self):
return self.email
def has_perm(self, perm, obj=None):
return super(VomUser, self).has_perm(perm, obj)
def has_module_perms(self, app_label):
return super(VomUser, self).has_module_perms(app_label)
def get_short_name(self):
return self.name
def get_username(self):
return self.name
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['name', 'birthday', 'sex', ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment