2

i try to make custom user model and i want to make super user but i am getting error like this

Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 390, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/commands/createsuperuser.py", line 50, in execute return super(Command, self).execute(*args, **options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 441, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/commands/createsuperuser.py", line 149, in handle self.UserModel._default_manager.db_manager(database).create_superuser(**user_data) TypeError: create_superuser() takes exactly 4 arguments (3 given) 

this is my model.py

class MyUserManager(BaseUserManager): def create_user(self, username, email, password=None): if not email: raise ValueError('Users must have an email address') user = self.model( email = self.normalize_email(email), username = username, ) user.set_password(password) user.save(using=self._db) return user def create_superuser(self, username, email, password): user = self.create_user(email,username=username, password=password) user.is_admin = True user.save(using=self._db) return user class Operator(AbstractBaseUser, PermissionsMixin): owner = models.ForeignKey('Owner') kontraktor = models.ForeignKey('Kontraktor') alphanumeric = RegexValidator(r'^[0-9a-zA-Z]*$', message='hanya yang mengandung karakter alphanumeric') email = models.EmailField(verbose_name='email address', unique=True, max_length=244) username = models.CharField(unique=True, max_length=20, validators=[alphanumeric]) first_name = models.CharField(max_length=30, null=True, blank=True) last_name = models.CharField(max_length=30, null=True, blank=True) date_of_birth = models.DateTimeField(auto_now_add=True) date_joined = models.DateTimeField(auto_now_add=True) is_active = models.BooleanField(default=True, null=False) is_staff = models.BooleanField(default=False, null=False) objects = MyUserManager() USERNAME_FIELD = 'email' REQUIRED_FIELD = ['username'] def get_full_name(self): fullname = self.first_name+" "+self.last_name return self.fullname def get_short_name(self): return self.username def __str__(self): return self.email 

can you help me solve this problem?

13
  • 1
    When do you receive that error? You haven't called it anywhere in the code above. Commented Jun 4, 2015 at 8:38
  • It's not the problem you mention, but note you are passing the values in the wrong order when you call create_user so that will fail. Commented Jun 4, 2015 at 8:40
  • when i try create super user in terminal @rnevius Commented Jun 4, 2015 at 8:41
  • so, how to do that? @DanielRoseman Commented Jun 4, 2015 at 8:42
  • Are you supplying a password? Also, as @DanielRoseman mentioned, fix the order of your values in the create_user method you're calling from create_superuser, to match how things are defined (username first, then email, then password). Commented Jun 4, 2015 at 8:44

1 Answer 1

4
REQUIRED_FIELD = ['username'] 

Should change to:

REQUIRED_FIELDS = ['username'] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.