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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:07:25+00:00 2026-05-11T05:07:25+00:00

I need to perform case-insensitive queries on username by default when using the Django

  • 0

I need to perform case-insensitive queries on username by default when using the Django Auth framework.

I tried fixing the issue by writing a custom subclass of Queryset and overriding the _filter_or_exclude method and then using that subclass in a custom manager for the User model-

from django.db.models import Manager from django.db.models.query import QuerySet from django.contrib.auth.models import UserManager  class MyQuerySet(QuerySet):     def _filter_or_exclude(self, negate, *args, **kwargs):         if 'username' in kwargs:             kwargs['username__iexact'] = kwargs['username']             del kwargs['username']         return super(MyQuerySet, self)._filter_or_exclude(negate, *args, **kwargs)  class MyUserManager(UserManager):     def get_query_set(self):         return MyQuerySet(self.model)  User.objects = MyUserManager() 

But this approach didn’t work and I am getting an weird error when I try doing User.objects.get(username='Foo').

Any help would be appreciated.

Update: I am including the exact error that I am getting.

/usr/lib/python2.5/site-packages/django/db/models/query.py in get(self, *args, **kwargs)     295         keyword arguments.     296         ''' --> 297         clone = self.filter(*args, **kwargs)     298         num = len(clone)     299         if num == 1:  /usr/lib/python2.5/site-packages/django/db/models/query.py in filter(self, *args, **kwargs)     481         set.     482         ''' --> 483         return self._filter_or_exclude(False, *args, **kwargs)     484      485     def exclude(self, *args, **kwargs):  /home/ghoseb/src/git/ocricket.git/ocricket/user/models.py in _filter_or_exclude(self, negate, *args, **kwargs)      38             kwargs['username__iexact'] = kwargs['username']      39             del kwargs['username'] ---> 40         return super(MyQuerySet, self)._filter_or_exclude(negate, *args, **kwargs)      41       42 class MyUserManager(UserManager):  /usr/lib/python2.5/site-packages/django/db/models/query.py in _filter_or_exclude(self, negate, *args, **kwargs)     499             clone.query.add_q(~Q(*args, **kwargs))     500         else: --> 501             clone.query.add_q(Q(*args, **kwargs))     502         return clone     503   /usr/lib/python2.5/django/db/models/sql/query.py in add_q(self, q_object, used_aliases)  /usr/lib/python2.5/django/db/models/sql/query.py in add_filter(self, filter_expr, connector, negate, trim, can_reuse, process_extras)  /usr/lib/python2.5/django/db/models/sql/query.py in get_meta(self)  <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute '_meta' 

Update: By the way, I just wanted to mention that when I copy the logic inside my _filter_or_exclude method into the actual QuerySet class, it works flawlessly.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T05:07:25+00:00Added an answer on May 11, 2026 at 5:07 am

    Managers can’t be added to classes with simple attribute assignment (User.objects = MyManager()). Look at the ModelBase metaclass (db/models/base.py) to see what all is done for you behind the scenes when you subclass Model.

    You should be able to make it work with User.add_to_class('objects', MyManager()). Alternatively, you could make a proxy subclass of User and add the manager there.

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

Sidebar

Ask A Question

Stats

  • Questions 116k
  • Answers 116k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I can't see how JPA would be permitted, but Hibernate… May 11, 2026 at 10:39 pm
  • Editorial Team
    Editorial Team added an answer I think the easiest way to do this is either… May 11, 2026 at 10:39 pm
  • Editorial Team
    Editorial Team added an answer Yes, there is a difference. From the java docs: Copy:… May 11, 2026 at 10:39 pm

Related Questions

First post, so here goes. I'm writing a script that does intelligent search and
I need to perform a complicated calculation. In my case it seemed most natural
I have a need to create a transactional process using an external API that
I have a few things that I cannot find a good way to perform

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.