Reputation: 9782
I am trying to set the boolean field of is_superuser
of the generic User
Django model to True
via the following code...
User.objects.create(username = 'Randy', email = '[email protected]', password = 'admin', is_superuser = True)
Does the is_superuser
field require anything else? Or am I doing something obviously wrong?
Things I have tried...
1) is_superuser = 'True'
2) is_superuser = 'true'
3) is_superuser = true
4) is_superuser = True
Upvotes: 0
Views: 1646
Reputation: 11916
'True'
is a Python string, not a boolean. It has to be True
. Your code worked perfectly for me. Let me copy paste from my Terminal:
>>> from django.contrib.auth.models import User
>>> user = User.objects.create(username = 'Randy', email = '[email protected]', password = 'admin', is_superuser = True)
>>> user
<User: Randy>
>>> user.is_superuser
True
>>>
However I see you used a plain text password. Please use make_password
for such cases:
https://docs.djangoproject.com/en/1.9/topics/auth/passwords/#django.contrib.auth.hashers.make_password
Upvotes: 6
Reputation: 1506
from django.contrib.auth.models import User
def blah(args):
User.objects.create_superuser(username='admin', password='123', email='')
Upvotes: 1