How to add a default value when creating users with Django's createsuperuser command

How can I customize the behavior of creating users through the createsuperuser command, that is, create a custom User class that inherits from AbstratUser and add the role attribute to it, what I want to do is that when creating an administrator user to Through the createsuperuser command, the value admin is assigned to the role attribute. As well as setting is_superuser to True, thank you for your attention.

1 Like

See the REQUIRED_FIELDS section in the CustomUser docs.

If that’s not a sufficient solution, then I would suggest you create a custom management command to create the users however you may need.

1 Like

Thank you, it works for me.