Question

I've been trying to get django-registration to work with Django 1.5 Configurable User Models.

I've seen some previous SO threads related to the error I'm having, but the solution to them doesn't seem to be working for me.

The error I get is:

"registration.registrationprofile: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL"

I understand this is related to the fact that django-registration doesn't seem to know about me using a custom user model, but I was under the impression this was fixed in the newer version.

The django-registration version I'm using says:

(0, 9, 0, 'beta', 1)

I don't think it has anything to do with my code as I've encountered this error on two projects using different code bases.

Just to cover the bases, though:

settings.py

AUTH_USER_MODEL = 'reg.MyUser'

and a cannibalized version of the Django 1.5 Customizable User Model guide I've been following:

models.py

class MyUserManager(BaseUserManager):
    def create_user(self, email):

        user = self.model(
            email=MyUserManager.normalize_email(email),
        )

        user.save(using=self._db)
        return user

class MyUser(AbstractBaseUser):
    email = models.EmailField(max_length=254, unique=True, db_index=True)

    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

Any help is appreciated in figuring out what's going wrong.

Jace

Was it helpful?

Solution

It doesn't seem to be updated to work with configurable user models yet based on the following lines from here

from django.contrib.auth.models import User

class RegistrationProfile(models.Model):
    user = models.ForeignKey(User, unique=True, verbose_name=_('user'))

OTHER TIPS

I am using django-registration VERSION = (1, 0, 0, 'final', 0) and have almost the same custom model (I have a couple of extra fields for name etc).

It works for me by following the changes here.

I haven't tried it but presume that you should just be able to make the changes to the imports at the top of the 2 files and then reset the other changes by using User = get_user_model as indicated in another post/link (not sure where I saw that now though).

I'm new to django and django-registration so I'm probably not aware of something but I don't see why this change couldn't be incorporated into the original module?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top