Regex Validators doesn't validate while working in a shell

127 views
Skip to first unread message

ashish...@finoit.co.in

unread,
Sep 12, 2016, 9:36:23 AM9/12/16
to Django users
I've configured user's username field in following way

username = models.CharField(
        _
('username'),
        max_length
=30,
        unique
=True,
        help_text
=_('Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.'),
        validators
=[
            validators
.RegexValidator(
                r
'^[\w.+-]+$',
                _
('Enter a valid username. This value may contain only '
                 
'letters, numbers ' 'and ./+/-/_ characters.')
           
),
       
],
        error_messages
={
           
'unique': _("A user with that username already exists."),
       
},
   
)

I'm getting error in admin panel but not in django-shell.




Though django raises an error for maximum length in shell.

Is it a bug? Or am I missing something.

Daniel Roseman

unread,
Sep 12, 2016, 9:45:29 AM9/12/16
to Django users
On Monday, 12 September 2016 14:36:23 UTC+1, ashish...@finoit.co.in wrote:
I've configured user's username field in following way

username = models.CharField(
        _
('username'),
        max_length
=30,
        unique
=True,
        help_text
=_('Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.'),
        validators
=[
            validators
.RegexValidator(
                r
'^[\w.+-]+$',
                _
('Enter a valid username. This value may contain only '
                 
'letters, numbers ' 'and ./+/-/_ characters.')
           
),
       
],
        error_messages
={
           
'unique': _("A user with that username already exists."),
       
},
   
)

I'm getting error in admin panel but not in django-shell.


Though django raises an error for maximum length in shell.

Is it a bug? Or am I missing something.


This has nothing to do with being in the shell.

Validators aren't run on save, and that is the case everywhere, as noted explicitly in the validators documentation: https://docs.djangoproject.com/en/1.10/ref/validators/#how-validators-are-run
-- 
DR.
Reply all
Reply to author
Forward
0 new messages