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 611187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:45:23+00:00 2026-05-13T17:45:23+00:00

I’m trying to learn Django and I would like feedback from anyone who has

  • 0

I’m trying to learn Django and I would like feedback from anyone who has any MVC/MTV/PHP/Ruby framework experience. Does anyone find that the user model is too tightly coupled with auth?

Background: When you first implement authentication for Django, you include the module django.contrib.auth

This will bring in several models like User, Group, Message etc. Let’s focus on the User model as this is the one of the most important tables in any website.

In short the User table has these fields

User

  • username max_length 30, unique, [letters, digits, underscores]
  • password max_length 75
  • email max_length 75
  • …and about 8 other useful fields like first_name, last_name, etc.

Goal:

I want to remove username and use email as the login for every user. It’s a pretty simple request that many websites use these days.

I don’t want to monkey patch the core code since this will make upgrading more difficult later on. This means modifying the User model is out of the question. I only want to do a few simple and basic things I expect a few frameworks to do so let me address how Django does it.

Adding new fields to the User model

Django docs says to use create another table and insert the fields there. You will have a one to one relationship between the User table and the Profile table.
eg.
If You want to add an image field to each user you add it to the profile table. A join query is made every single time. They’ve even specified a constant to tell the framework what table to use:
AUTH_PROFILE_MODULE = ‘accounts.UserProfile’
I don’t think it’s the best practice to have to do a join query every time I want a field that should belong to the user table.

Another option is to use the function add_to_class.
The django community has stated it’s not good to define new fields outside of the main class because other developers who add methods won’t know all the data members.

Editing old fields

The auth module does a check against two fields username and the hashed password. Looking at the above table I would need to change the username model to accept these properties. Length of 75 with all the valid characters of the email. The django suggests I check against the email field.

Two problems arise if I use the email field to auth against:
I need to write a new class to be used in a constant AUTHENTICATION_BACKEND, so it checks against the email field and I have an unused field called username.

Adding new methods

In MVC/MTV a design principle is to use fat models skinny controllers. Since the model is declared in auth, I’m not sure how one is supposed to add methods that act on the user model’s fields. Since django suggests using a Profile model, I suppose they will have to go there.

Extending the User class

A small annoyance would be that I can’t use the name ‘User’ and instead must use ‘Users’ or ‘Accounts’. A bigger one is I don’t think the auth would recognize this new module. Meaning I would have to rewrite a bunch functionality that is is present. This one doesn’t bother me as it’s something I expect to do in other frameworks.

Any comments are appreciated. I wouldn’t ask all these questions and look for solutions if I wasn’t truly interested in using django.

  • 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-05-13T17:45:23+00:00Added an answer on May 13, 2026 at 5:45 pm

    I agree that django’s incessant clinginess to the auth models is absurd. My job requires me to create ultra scalable and very high load sites which sometimes require user authentication and djano’s auth model + permissions does not fit with that.

    Fortunately, it’s not difficult to replace.

    First, create a custom User model.

    class User(models.Model):
        ...fields...
        #Define some interface methods to be compatible.
        def get_and_delete_messages(self):
        def is_active(self):
        def is_anonymous(self):
        def is_authenticated(self):
        def is_staff(self):
        def has_perm(self, perm_list):
    

    Second, create your own authentication back-end.

    class LocalAccount(object):
        """
        This checks our local user DB for authentication
        """
        def authenticate(self, username=None, password=None):
            try:
                user = User.objects.get(alias=username)
                if user.check_password(password):
                    return user
            except User.DoesNotExist:
                return None
    
        def get_user(self, user_id):
            try:
                return User.objects.select_related().get(pk=user_id)
            except User.DoesNotExist:
                return None
    
    #settings.py
    AUTHENTICATION_BACKENDS = (
        'helpers.auth.LocalAccount',
    )
    

    That should solve most of your issues, I don’t even think all of the methods you would find on django.contrib.auth.User are necessary, I recommend trying it out.

    The one gotcha here is that the admin may start to bitch, fortunately that’s really easy to patch using simple python inheritance as well. That’s another question though 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.