Im new to django and trying to make a user registration form with few validations. Apart from this I also want a username suggestion code which will tell the user if the use
Check out the django-registration application. And have a look at the Class registration.forms.RegistrationForm and their method clean_username.
It should be easy to extend the form to suggest some usernames.
here is some sample code to generate unique username with numbered postfixes:
username # filled with user input or first/lastname etc.
#check for other profile with equal names (and those with a postfix)
others = [int(username.replace(name, "0"))
for p in User.objects.filter(username__startswith=username).exclude(user=self.user)
if username.replace(name, "0").isdigit()]
#do we need a postfix
if len(others) > 0 and 0 in others:
username = "%s%d" % (username, max(others) + 1)
you could fill the generated names in a Form Choice Field: http://docs.djangoproject.com/en/dev/ref/forms/fields/#choicefield