请问Django1.5 自定义User模块在做执行syncdb操作时遇到类型错误问题,django1.5syncdb,django1.5 自定
请问Django1.5 自定义User模块在做执行syncdb操作时遇到类型错误问题,django1.5syncdb,django1.5 自定
django1.5 自定义User模块后执行 syncdb 总是报错 TypeError: create_superuser() takes exactly 4 arguments (3 given)
源码如下:
# coding: utf8from django.db import modelsfrom django.contrib.auth.models import BaseUserManager, AbstractBaseUser# Create your models here.class PassportManager(BaseUserManager): def create_user(self, email, alias, password=None): # create_user()参数必须是USERNAME_FIELD 和 所有的REQUIRED_FIELD if not email: raise ValueError('用户必须输入Email地址') user = self.model( email = PassportManager.normalize_email(email), alias = alias, # is_staff = False, # is_active = True, # is_superuser = False ) user.set_password(password) user.save(using = self._db) return user def create_superuser(self, email, alias, password): # 创建超级用户,一般来说可以直接调用create_user方法,然后设置管理员相关属性, user = self.create_user( email = email, alias = alias, password = password ) user.is_admin = True # is_admin = True 等同于以下: # user.is_staff = True # user.is_active = True # user.is_superuser = True user.save(using = self._db) return userclass Passport(AbstractBaseUser): email = models.EmailField(max_length=254, unique=True, db_index=True) alias = models.CharField(max_length=60) is_active = models.BooleanField('active', default=True) is_admin = models.BooleanField('staff status', default=False, help_text='flag for log into admin site.') avatar = models.ImageField(upload_to='avatar', max_length=255) bio = models.CharField(max_length=255) GENRE_CHOICES = ( (1, '摄影师'), (2, '插画师'), (3, '原画师'), (4, '平面设计师'), (5, '品牌顾问'), (6, '其他'), ) genre = models.SmallIntegerField(choices=GENRE_CHOICES) site_dribbble = models.URLField(blank=True, verbose_name=u'Dribbble') site_deviantart = models.URLField(blank=True, verbose_name=u'DeviantART') site_benhance = models.URLField(blank=True, verbose_name=u'Benhance') site_tumblr = models.URLField(blank=True, verbose_name=u'Tumblr') site_zcool = models.URLField(blank=True, verbose_name=u'站酷') site_blog = models.URLField(blank=True, verbose_name=u'博客') site_sina = models.URLField(blank=True, verbose_name=u'新浪微博') # 用于登录的字段 USERNAME_FIELD = 'email' # REQUIRED_FIELDS must contain all required fields on your User model, # but should not contain the USERNAME_FIELD or password as these fields # will always be prompted for. REQUIRED_FIELD = ['alias'] objects = PassportManager() def get_full_name(self): return self.alias def get_short_name(self): return self.alias def __unicode__(self): return self.alias @property def is_staff(self): # Is the user a member of staff? # Simplest possible answer: All admins are staff return self.is_admin
Google 上有一些提问,但是好像全部都是集中在 REQUIRED_FIELD = ['']的问题,然后我逐一检查了下,以我的理解应该是没有问题的了...
http://python.6.x6.nabble.com/Syncdb-error-with-new-1-5rc1-td5001568.html
https://groups.google.com/d/topic/django-users/RnPEUEAvvE0
编橙之家文章,
相关内容
- 请教关于ubuntu导入python-opencv ImportError问题,,这个问题
- Django设置ForeignKey初始参数有什么好建议,djangoforeignk
- Python如何保存编辑器配色方案,python配色方案,各位:每
- Django queryset reduce综合应用问题,djangoqueryset,我现在有一
- Django单元测试factory_boy与model_mommy推荐哪个最适用,dj
- pyqt处理长时任务,pyqt处理长任务,有一个任务是用pan
- 用python抓新浪首页,返回的是乱码,python新浪首页,这是
- django haystack 中使用 Spatial Search order_by 的一个问题,d
- flask如何备份和迁移mysql,flask迁移mysql,在flask的教程里
- 现在在写app服务器的一些功能,以前没有接触过服务器
评论关闭