简体   繁体   中英

Django Registration with Custom User Model

So I am using a custom user model accounts.player and i'm also using django-registration in my project.

With the custom model it now encounters an error. I know I could just write my own registration code but is there a way to use the custom model class with django-registration. I had a look on the docs but didn't really find a solution.

I'm sure theres probably a way using something like a subclass but i'm not sure how to implement this.

What files are required and what code would I need??

This is what I did for a personal project of mine:

class UserProfile(models.Model):

    user = models.OneToOneField(User, related_name = 'MoreAboutUser', unique=True)
    age = ....
    gender = ....

Regarding your error, I don't know how to help you since you didn't provide any traceback/code. But you can connect your custom model with the User model with a OneToOneFiel'

You could either Fork django-registration and make changes to Make it work with Custom User model... But that would be a long process...

Or

You could switch to django-allauth , which is a better and well maintained Registration app for Django. It is compatible with Latest django version and also provides social registration out of the box

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