views:

70

answers:

1

Hi All, 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 username he is trying to register is available or already in use. Then it should give few suggestions that might be available to choose from. Can anyone who might have worked on the same or somewhat same project help me with this.

Thanks

+2  A: 

You can handle this by overriding the clean method of the corresponding field in the form:

def clean_username(self):
    if 'username' in self.cleaned_data:
        username = self.cleaned_data.get('username')
        #DO YOUR CHECK
        if THERE_IS_ALREADY_SUCH_USERNAME:
            err = _(u'This username already exists. Try one of the following: %(sug)s)' % SUGGESTIONS)
            raise forms.ValidationError(err)
        return username
aeby
Hi aeby, Thanks for that post. I got that working now and now my django form is checking if the user already exists or not but can you help me writing some suggestion script...to check for few suggestions..hope u knw wat i mean....thankx
itsandy