1๐
You could use a CustomUserManager
and in the create_user()
method, do a case insensitive check to see if the username is already present with iexact
๐คEwan
1๐
I think I have a solution:
def clean_username(self):
kwargs = {
'{0}__{1}'.format(UsernameField(), 'iexact'): self.cleaned_data['username'],
}
if User.objects.filter(**kwargs):
raise ValidationError(_('A user with that username already exists.'), code='invalid')
return self.cleaned_data['username']
UsernameField() is from django-registration-redux.
If there are any problems with this approach, please say!
๐คStringsOnFire
- [Answered ]-Control consume speed of celery worker
- [Answered ]-Django Shell in Eclipse not starting
- [Answered ]-Django Sessions not Working
0๐
I do it with RegistrationFormCaseInsensitive form from django_registration (https://pypi.org/project/django-registration/)
After install:
In admin.py:
from django.contrib.auth.models import AbstractUser
from django.db import models
class CustomUser(AbstractUser):
pass
Create forms.py with:
from django_registration.forms import RegistrationFormCaseInsensitive
from .models import CustomUser
class CustomUserForm(RegistrationFormCaseInsensitive):
class Meta(RegistrationFormCaseInsensitive.Meta):
model = CustomUser
in urls.py add one of this imports:
for one step registration:
from django_registration.backends.one_step.views import RegistrationView
or for registration with mail link:
from django_registration.backends.activation.views import RegistrationView
and then add the path:
path("accounts/register/",
RegistrationView.as_view(
form_class=CustomUserForm,
success_url="/"
), name="django_registration_register"),
๐คMarco Giuliani
- [Answered ]-Django โ Generate shortest random slug
- [Answered ]-Auto-incrementing Django DateField
- [Answered ]-How to restrict certain fields in a model based on the user in django
- [Answered ]-Django bootstrap to have both call a view and modal in same anchor tag
Source:stackexchange.com