I had the same issue but I also wanted to create additional data for
each user. It was straightforward to create a script to add users.

I needed to import some bits to set up the Django environment and then
I was able to create users with standard Django calls.  Here is
extracts from my code (with my custom tables omitted).  This also
include setting of the raw password (Django will hash it for you).
The code could probably be made more elegant but it works.

# Setup Django environment
import settings # Assumed to be in the same directory.
from django.core.management import setup_environ
setup_environ(settings)

from django.contrib.auth.models import User
import django.contrib.auth

def create_user( username, first_name, last_name, email,
raw_password):
    new_user = User(username=username, first_name=first_name,\
        last_name=last_name, email=email)
    new_user.set_password(raw_password)
    new_user.save()

member_set = [\
['biggles', 'Biggie', 'Bigglesworth', 'bigg...@raf.org'],\
['algie', 'Algernon', 'Sidekick', 'al...@raf.org'],\
['grumpy', 'Grumpy', 'Dwarf', 'gru...@7dwfs.com'],\
['sleepy', 'Sleepy', 'Dwarf', 'sle...@7dwfs.com'],\
['dopey', 'Dopey', 'Dwarf', 'do...@7dwfs.com'],\
['doc', 'Doc', 'Dwarf', 'd...@7dwfs.com'],\
]

for one in member_set:
    create_user( one[0], one[1], one[2], one[3], one[0])


On Mar 22, 12:26 pm, Ivan Uemlianin <i...@llaisdy.com> wrote:
> Dear All
>
> I'd like to create a bunch of sample users for testing a django
> website.  I was going down the road of using an initial_data fixture,
> but there seem to be a couple of problems with this:
>
> - Can I supply partial data in initial_data, i.e. only auth.user info
> (at the moment, username and password, and it seems to require last
> login)?  When I do this, syncdb persists in asking me for an admin
> user (even when the previously given admin user still works).
>
> - How should I specify the password field in the fixture?  dumpdata
> outputs a hash.  Do I need to write some script to generate hashes
> from given passwords?
>
> I'm now thinking a fixture might not be the right way to go: it might
> be better to have a little script to add users once syncdb is done.
> As well as allowing me to provide plain text passwords, I could easily
> add site-specific attributes when I need them (dave.favourite_colour =
> 'orange'; bob.online = True, etc).
>
> Is that second method just reinventing the fixture, or is it more
> appropriate here?
>
> Thanks and best wishes
>
> Ivan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to