django-registration 1.0 now has support for django 1.5 custom user models. The django-registration documentation only has the following FAQ item about it:
I’m using Django 1.5 and a custom user model; how do I make that work?
Although the two built-in backends supplied with django-registration both assume Django’s default User model, the base view classes are deliberately user-model-agnostic. Simply subclass them, and implement logic for your custom user model.
I'm not sure which views I need to subclass and what should go in them. I've also noticed that the ProfileManager
in django-registration still assumes a separate username field.
In my specific case, I've removed the 'username' field, added a 'display_name', and made 'email' the identifying field:
class MyUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(
verbose_name="Email Address",
max_length=384,
unique=True,
db_index=True,)
display_name = models.CharField(max_length=128, blank=True)
date_joined = models.DateTimeField(default=timezone.now)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
objects = MyUserManager()
USERNAME_FIELD = 'email'
def get_full_name(self):
return self.email
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
Without subclassing any django-registration classes, the default rendering of the registration form pulls in fields from User
instead of MyUser
.
I've seen the following SO thread django-registration app and Django 1.5 custom user model, but it didn't help.
Update
I've noticed that RegistrationForm is hardcoded with a 'username' field. The FAQ only mentions subclassing the backend, so I'm not sure what the intention is here. Should I subclass the form as well?
DefaultBackend
,RegistrationFormFromUserModel
as well asRegistrationManager
for this. – pankaj28843form
template tag. Not ideal, but I think it might be the simplest option. – bnjmn