2

假设我从 django 用户类继承:

# import AbstractUser class ....
class MyUser(AbstractUser):

    gender = models.Charfield(....
    ....
    # I want to make the email field blank=False and unique=True
    # however, to my knowledge, python doesn't allow you to 
    # override inherited fields

那么如何使电子邮件字段为空白=假和唯一=真。注意:我也在使用 South,所以 South 友好的代码会很好。(注意:我使用的是 Django 1.5,所以希望有一个解决方案,这样我就不必从 AbstractBaseUser 创建自己的用户模型)

4

1 回答 1

2
class MyUser(AbstractUser):

    gender = models.Charfield(....

    def __init__(self, *args, **kwargs):
       super(self, MyUser).__init__(*args, **kwargs)
       email = models.EmailField(blank=False, unique=True)
       email.contribute_to_class('email', self)
于 2013-03-08T14:33:19.393 回答