How to add SUPERuser(not just user) through Django fixtures?
Let's say I wanna have login:admin, password:admin.
fixtures . A fixture is a collection of data that Django knows how to import into a database. The most straightforward way of creating a fixture if you've already got some data is to use the manage.py dumpdata command.
You must create a directory in your app named fixtures and put your fixtures files there. You can write them in json or xml, one easy way to make them is to create some objects in the admin interface and then run manage.py dumpdata. That would dump the data from the objects you created into fixture files.
On empty database:
python manage.py createsuperuser python manage.py dumpdata auth.User --indent 4 > users.json
and in users.json
You have needed fixtures.
./manage.py shell >>> from django.contrib.auth.hashers import make_password >>> make_password('test') 'pbkdf2_sha256$10000$vkRy7QauoLLj$ry+3xm3YX+YrSXbri8s3EcXDIrx5ceM+xQjtpLdw2oE='
and create fixtures file:
[ { "model": "auth.user", "pk": 1, "fields": { "username": "admin", "password": "pbkdf2_sha256$10000$vkRy7QauoLLj$ry+3xm3YX+YrSXbri8s3EcXDIrx5ceM+xQjtpLdw2oE=" "is_superuser": true, "is_staff": true, "is_active": true } } ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With