ModelForm based on User allows any username without checking

2012-04-04 Thread Bastian
Hi, I have a form that asks the registering user to choose a username. That form is a ModelForm based on the django.contrib.auth.models Users: class usernameForm(forms.ModelForm): class Meta: model = User fields = ('username', ) The strange thing is that when it appears on t

Re: ModelForm based on User allows any username without checking

2012-04-05 Thread Pavan Verma
Hi Bastian, you need to define the restrictions on the username field. It can be done by including the code below inside usernameForm. This code is from django/contrib/auth/forms.py -> UserCreationForm, you can refer it to understand further. username = forms.RegexField(label="Username", max_l

Re: ModelForm based on User allows any username without checking

2012-04-09 Thread Bastian
Yes that's what I ended up doing but isn't it supposed to be automatic, coming from the restrictions of the model since it's a ModelForm? On Thursday, April 5, 2012 7:51:14 PM UTC+2, Pavan Verma wrote: > > Hi Bastian, > you need to define the restrictions on the username field. It can be > done

Re: ModelForm based on User allows any username without checking

2012-04-09 Thread Pavan Verma
I went through django/contrib/auth/models.py to check the definition of the User model. I don't see this file defining any restrictions on what a username can be. So, I think the form is the place (and possibly the only place) which defines and enforces restrictions on what the username can be. In

Re: ModelForm based on User allows any username without checking

2012-04-10 Thread Bastian
I assumed restrictions would apply at model level but it's not the case. About the ModelForm, isn't it the point of using a ModelForm? (with the User model as shown in the example of course) that it inherits from the model and automatically creates the right fields, widgets, and restrictions? r