如何在Django中一起使用CustomUser模型和OpenID进行身份验证?

时间:2011-05-08 19:27:37

标签: python django django-models openid

我正在学习Python Django框架。感谢StackOverFlow社区,我已经学会了如何在django中使用open-id(social_auth我正在使用)。

使用social_auth,登录和退出流程非常简单实用。但是我想在用户之间建立友谊关系,为此我创建了新的模型类,它从from django.contrib.auth.models import User扩展并在auth_table中创建新用户时添加控件,我在CustomUser Table上创建新用户。(它效率不高。)因为来自open-id的参数对于每个open-id连接是不同的) 我的型号代码在这里

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")

如何在Django中一起使用CustomUser模型和OpenID进行身份验证?

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

在Django中扩展User类的方法是提供用户配置文件类。见here。然后,您可以像往常一样使用用户模型,并根据需要获取配置文件实例。