0

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

3
  • I have just started getting a view with the field requirements....stuck on how to connect it to postgresql db....and get the data whn submit button is pressed...can u help... Commented Apr 27, 2010 at 23:05
  • You have posted exactly the same question twice: stackoverflow.com/questions/2719292/django-forms-help-needed/… Maybe you show first read the Manual docs.djangoproject.com/en/dev/ref/forms/validation Commented Apr 29, 2010 at 8:44
  • yeah i know it has been posted twice. I apologise for that actually when i posted it first it didnt come up in the question section so I thot here would be a problem so I posted again. ;) thnx for the reply tho.. Commented Apr 30, 2010 at 0:06

1 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.