说我继承了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
那么如何使电子邮件字段为空= False且unique = True。注意:我也使用South,所以South友好的代码会很好。 (注意:我正在使用Django 1.5,所以希望有一个解决方案,所以我不必从AbstractBaseUser创建自己的用户模型)
答案 0 :(得分: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)