The question about databases.
Do I understand correctly that if we create a MyUser class (as in your
example) then extra fields (e.g. date_of_birth) will be stored in the same
table of a database with inherited fields (from AbstractBaseUser)?
> ===
> from django.db import models
>
> from django.contrib.auth.models import BaseUserManager, AbstractBaseUser
>
> class MyUserManager(BaseUserManager):
> def create_user(self, email, date_of_birth, password=None):
> if not email:
> raise ValueError('Users must have an email address')
>
> user = self.model(
> email=MyUserManager.normalize_email(email),
> date_of_birth=date_of_birth,
> )
>
> user.set_password(password)
> user.save(using=self._db)
> return user
>
> def create_superuser(self, username, password, date_of_birth):
> u = self.create_user(username, password=password,
> date_of_birth=date_of_birth)
> u.is_admin = True
> u.save(using=self._db)
> return u
>
>
> class MyUser(AbstractBaseUser):
> email = models.EmailField(verbose_name='email address',
> max_length=255, unique=True)
> date_of_birth = models.DateField()
> is_admin = models.BooleanField(default=False)
>
> objects = MyUserManager()
>
> USERNAME_FIELD = 'email'
> REQUIRED_FIELDS = ['date_of_birth']
>
> def get_full_name(self):
> return self.email
>
> def get_short_name(self):
> return self.email
>
> def __unicode__(self):
> return self.email
>
> # Admin required fields
> 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_active(self):
> return True
> ===
>
> * Set AUTH_USER_MODEL = 'myauth.MyUser'
>
> * Run syncdb.
>
> At this point, feedback and offers of assistance are most welcome.
>
> [1]
> https://code.djangoproject.com/wiki/ContribAuthImprovements#Recommendations
> [2] https://github.com/freakboy3742/django/tree/t3011
> [3] http://www.w3.org/International/questions/qa-personal-names
>
> Yours,
> Russ Magee %-)
>
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-developers/-/e_eXtydc004J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.