PASSWORD = '123' # replace this with something good
EMAIL = 'aafshar@gmail.com'
import pexpect
# spawn the child process
child = pexpect.spawn('python manage.py syncdb')
# Wait for the application to give us this text (a regular expression)
child.expect('Would you like to create one now.*')
# Send this line in response
child.sendline('yes')
# Again wait for this, and send what is needed
child.expect('Username.*')
# A blank string for the default username
child.sendline('')
# And so it goes on
child.expect('E-mail.*')
child.sendline(EMAIL)
child.expect('Password.*')
child.sendline(PASSWORD)
child.expect('Password.*')
child.sendline(PASSWORD)
# This means wait for the end of the child's output
child.expect(pexpect.EOF, timeout=None)
Comments
Good solution for restoring the admin stuff when
django-admin.py reset appisn't enough and you have to recreate the whole db.Another method, which works for non-admin stuff too, is to create a little script that you run like
python devel_populate.py(example below). The only caveat is that you need to set up your PYTHONPATH and DJANGO_SETTINGS_MODULE first (ie. usingdjango-admin.pynotmanage.py).#