如何使用Django 1.5创建自定义用户配置文件?

时间:2013-03-09 19:35:33

标签: python django

如何使用Django 1.5创建新的自定义用户配置文件?我不清楚文档

例如我需要:

class StandardProfile(models.Model):
    name = models.CharField(max_length=255) #or ForeignKey(User)
    email = models.CharField(max_length=255) #or ForeignKey(User)
    password = models.CharField(max_length=255) #or ForeignKey(User)
    full_name = models.CharField(max_length=255)
    something = models.CharField(max_length=255)

class ArtistProfile(models.Model):
    name = models.CharField(max_length=255) #or ForeignKey(User)
    email = models.CharField(max_length=255) #or ForeignKey(User)
    password = models.CharField(max_length=255) #or ForeignKey(User)
    full_name = models.CharField(max_length=255)
    style = models.CharField(max_length=255)
    music = models.CharField(max_length=255)
    bank_account = models.CharField(max_length=255)

如何将此更改为新用户自定义模型?

(我想用来验证用户:https://docs.djangoproject.com/en/dev/topics/auth/

1 个答案:

答案 0 :(得分:2)

您将无法使用django 1.5的Custom User Model,因为您只能拥有这样的一个模型。

在您的情况下,您可能希望在ProfilesUser模型之间设置OneToOne relationship

from django.contrib.auth.models import User

class StandardProfile(models.Model):
    user = models.OneToOneField(User, primary_key=True)
    something = models.CharField(max_length=255)

class ArtistProfile(models.Model):
    user = models.OneToOneField(User, primary_key=True)
    style = models.CharField(max_length=255)
    music = models.CharField(max_length=255)
    bank_account = models.CharField(max_length=255)