Users in initial data fixture

后端 未结 6 1669
臣服心动
臣服心动 2021-01-31 01:50

I\'m creating a few users by default in my fixtures/initial_data.json so as to have some testing \"subjects.\" The problem I\'m experiencing is password generation.

6条回答
  •  伪装坚强ぢ
    2021-01-31 02:13

    What might be easier in this case (and if you only need a few users) is to create some fake user accounts through the admin (including passwords) and then dump the users to a fixtures file using dumpdata:

    $ python manage.py dumpdata auth.User --indent 4 > users.json
    

    which will automatically create the fixtures for you and can be used later with loaddata

    (You could just create one fake account and use the hash in the rest of your fixtures if you needed lots of test users)

    https://docs.djangoproject.com/en/dev/ref/django-admin/#dumpdata-appname-appname-appname-model

提交回复
热议问题