Django createsuperuser

Hello, how to include first_name, and last_name when executing the command python manage.py createsuperuser and update some field on the model (setting is_approve to True)?

class CustomUser(AbstractUser):
    employee = models.ForeignKey(Employee, null=True, blank=True, on_delete=models.CASCADE)
    is_approve = models.BooleanField(default=False)
    password_expiration = models.IntegerField(default=90)
    attempts = models.IntegerField(default=4)
    is_lock = models.DateTimeField(blank=True, null=True)

    # Emails
    pending_email = models.EmailField(blank=True, null=True)
    is_pending_email = models.BooleanField(default=False)

    # Time
    time_zone = models.CharField(max_length=50, default='Asia/Manila')

    # Task In Task Out
    task_in = models.DateTimeField(blank=True, null=True)
    task_out = models.DateTimeField(blank=True, null=True)
    current_task = models.CharField(max_length=150, default='Task', blank=True, null=True)

    is_ready = models.BooleanField(default=False)
    is_working = models.BooleanField(default=False)
    is_prod = models.BooleanField(default=False)
    
    task_start_time = models.DateTimeField(blank=True, null=True)
    task_end_time = models.DateTimeField(blank=True, null=True)

    # For Production task
    track_task_id = models.CharField(max_length=100, blank=True, null=True, editable=False)
    track_table_id = models.IntegerField(default=-1, blank=True, null=True, editable=False)
    #
     
    # Old    
    is_defer = models.BooleanField(default=False)
    defer_continue = models.DateTimeField(blank=True, null=True)
    defer_time = models.DateTimeField(blank=True, null=True)
    defer_count = models.IntegerField(default=0, blank=True, null=True)
    total_time_spent = models.CharField(max_length=25, blank=True, null=True)

    defer_task = models.CharField(max_length=100, blank=True, null=True, editable=False)
    defer_table = models.IntegerField(default=-1, blank=True, null=True, editable=False)

See the docs for the createsuperuser command and the REQUIRED_FIELDS model attribute for custom User models for your options in allowing for the entry of additional fields.

2 Likes

Custom Users in Django inherit from AbstractUser or AbstractBaseUser, you have to add this fields in class:

  • Django uses field (username) as user identifier if you want to change it to anything must override it inside class

  • also required fields too need to add this inside class too with all field you need to be required link last name or first name

      REQUIRED_FIELDS = ['first_name', 'last_name']
      USERNAME_FIELD = 'username' 
    

change to email as example

1 Like