Note that there are some explanatory texts on larger screens.

plurals
  1. POSubclassing django-registration 1.0 forms for django 1.5 custom user models
    text
    copied!<p>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:</p> <blockquote> <p><strong>I’m using Django 1.5 and a custom user model; how do I make that work?</strong></p> <p>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.</p> </blockquote> <p>I'm not sure which views I need to subclass and what should go in them. I've also noticed that the <code>ProfileManager</code> in django-registration still assumes a separate username field.</p> <p>In my specific case, I've removed the 'username' field, added a 'display_name', and made 'email' the identifying field:</p> <pre><code>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 </code></pre> <p>Without subclassing any django-registration classes, the default rendering of the registration form pulls in fields from <code>User</code> instead of <code>MyUser</code>.</p> <p>I've seen the following SO thread <a href="https://stackoverflow.com/questions/15296295/django-registration-app-and-django-1-5-custom-user-model">django-registration app and Django 1.5 custom user model</a>, but it didn't help.</p> <p><strong>Update</strong></p> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload