Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:50:11+00:00 2026-06-09T14:50:11+00:00

Currently, in django.contrib.auth, there can be two users with the username ‘john’ and ‘John’.

  • 0

Currently, in django.contrib.auth, there can be two users with the username ‘john’ and ‘John’. How can I prevent this from happening.

The most straightforward approach is add a clean method in contib.auth.models and convert it to a lowercase before saving but i dont want to edit the contrib.auth package.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:50:12+00:00Added an answer on June 9, 2026 at 2:50 pm

    Listen on pre_save for the Users model and then do your checks there. Least intrusive and most portable way.

    Here is an example on how this would look like (adapted from the user profile example):

    def username_check(sender, instance, **kwargs):
        if User.objects.filter(username=instance.username.lower()).count():
           raise ValidationError('Duplicate username')
    
    pre_save.connect(username_check, sender=User)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that looks like this: from django.db import models from django.contrib.auth.models
Currently I have the from django.contrib.auth.models import User but I'm confused as to how
Currently, this is how I do my login: (r'^login/?$','django.contrib.auth.views.login',{'template_name':'login.html'}), I'm using Django's built in
Basically, I currently have login/ in urls.py redirect to the django.contrib.auth.views.login and that seems
I have inserted this in settings.py: AUTHENTICATION_BACKENDS = ( 'blog.auth.backends.EmailBackend', 'django.contrib.auth.backends.ModelBackend', ) blog is
Can you use contrib.auth.models.User or any of contrib.auth along with Django MongoDB Engine ?
I want a nice convenient attribute to do the following: from django.contrib.auth.models import User
I am currently using the forms in django.contrib.auth to change a user password, but
Currently, django.contrib.comments sends the user to the preview page if there is any error
I have the following: from django.contrib.auth.models import User class ClientDetails(models.Model): created_by = models.ForeignKey(User) ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.