Auto Creation (Domain, Username, Password)


#1

Hi all,

I have tried a few options for auto-creating various fields, but none have worked. At the moment, I would like to focus on an auto-generated username and password (for an external site). The domain would be nice, but I can probably figure that out if I can get the other two working.

For the username, I would like the result to be something like:

username = first_name + last_name + str(integer)

The username seems simple enough, but I am having a hard time figuring where to put that code. Would it go in models.py? Do you write it as a separate variable under the other code? I feel like I may have missed this part in the instructions.

For the password I would like a random selection of letters and numbers (length=10). I have tried the following in models.py:

password = get_random_string(length=10)

and

password = BaseUserManager().make_random_password(length=10, allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789')

Neither worked, despite importing get_randon_string and BaseUserManager.

Any ideas? Currently my coworker is manually creating all three fields and pasting them into an Excel spreadsheet. I’d love to give him this app with this functionality sorted.

Thank you!


#2

That’s because Hello Web App doesn’t go into this. :D In the book, we use Django’s User model which has a lot of built in stuff, as well as django-registration-redux which builds login pages that assume we want our user to provide their own username/pw.

Maybe this posting in Stack Overflow will help?

Sounds like you’ll need to create your own User manager.

I’d recommend posting this on Stack Overflow actually — I think the users there can help you way more than I could, as I’ve never done this before! I’m sure they can help. :)


#3

Wonderful! Thank you.