How to use CustomUser model and OpenID together in Django for authentication?
I'm learning Python Django framework. Thanks to StackOverFlow Community, i have learned how to use open-id in django (social_auth i'm using ).
with social_auth, sign in and sign out process are pretty easy and practical. But i want to build friendship relationship between users, for this i created new model class which is extended from from django.contrib.auth.models import User
and add control when new user is created in auth_table, i create new user on CustomUser Table.(It is not efficient because the parameters coming from open-id are different for each open-id connection)
My model code is here
from datetime import datetime
from django.core.exceptions import ObjectDoesNotExist
from开发者_高级运维 django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import UserManager
# Create your models here.
class CustomUser(User):
gender = models.CharField(max_length=50)
location = models.CharField(max_length=50)
bio = models.CharField(max_length=50)
web_pages = models.CharField(max_length=50)
friends = models.ManyToManyField("self")
And How can i use CustomUser model and OpenID together in Django for authentication?
Any Help will be appreciated.
The way to extend the User class in Django is to provide user profile class. See here. You can then just use the User model as always and get the profile instance on demand.
精彩评论