1

I want to run my custom command from django view which create new user. Here is my command

python manage.py  tenant_command createsuperuser --schema=schema_name

Here schema name my be change

Above command is same as

python manage.py createsuperuser

Here i didn't know how to pass username, email and password and confirm password any suggestion would be appreciated

5
  • 1
    Does this answer your question? Run custom admin command from view Commented Feb 27, 2020 at 5:55
  • up-to some level but i also need to pass username, email, and password, here I'm using custom user model extends from abstract base user Commented Feb 27, 2020 at 6:03
  • check this - stackoverflow.com/questions/6244382/… Commented Feb 27, 2020 at 6:12
  • Why use a management command? Just create the User using the User API Commented Feb 27, 2020 at 10:50
  • Yeah you are right, that was my mistake Commented Feb 27, 2020 at 11:02

1 Answer 1

2

There are two ways to achieve what you trying to do:

  • Using code to change the user object and save it to database
  • Calling the command you mentioned

According to django docs you can call your commands in code using call_command function, it takes arguments and pass them to command too:

call_command("custom_command", arguments..)

In the other way you have access to User model in your view so you can import it directly and create the user:

from django.contrib.auth impor get_user_model

get_user_model().objects.create()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for you helps, Here I'm using different schema for different tenants, somethings like isolated schema, Anyway I've solved my issue

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.