简体   繁体   中英

Social-auth-django with custom uer model use OneToOneField link to auth.User

I have a customer model extends django auth.User like:

class CustomerUser(models.Model):
    user = models.OneToOneField(User,
                                related_name='customeruser',
                                on_delete=models.CASCADE)
    secondary_email = models.EmailField(blank=True, unique=True, null=True)
    created_time = models.DateTimeField(
        auto_now_add=True,
        db_index=True
    )

In my setting.py:

SOCIAL_AUTH_USER_MODEL = 'account.models.CustomerUser'

and err msg look like:

ValueError: Invalid model reference 'account.models.CustomerUser'. String model references must be of the form 'app_label.ModelName'.

What should I do that I can craete a customeruser and make it references to auth.User?

replace User with settings.AUTH_USER_MODEL and add from django.conf import settings

user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM