Last active
April 15, 2023 11:43
-
-
Save makeittotop/f0df9644088b4d54cbcc to your computer and use it in GitHub Desktop.
Create / remove user / superuser in a django app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from django.contrib.auth.models import User | |
# Create a regular user 'foo' | |
>>> user = User.objects.create_user('foo', '[email protected]', 'bar') | |
# List all users | |
>>> User.objects.all() | |
[<User: admin>, <User: abegail>, <User: foo>] | |
>>> User.objects.all()[1].is_superuser | |
True | |
>>> User.objects.all()[2].is_superuser | |
False | |
# Drop a user from the db | |
>>> User.objects.all()[2].delete() | |
>>> User.objects.all() | |
[<User: admin>, <User: abegail>] | |
# Create a superuser | |
>>> user = User.objects.create_superuser('burr', '[email protected]', 'buzz') | |
>>> User.objects.all() | |
[<User: admin>, <User: abegail>, <User: burr>] | |
>>> User.objects.all()[2].delete() | |
>>> User.objects.all() | |
[<User: admin>, <User: abegail>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
truly helpful it really helped me , thank u