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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:34:19+00:00 2026-05-27T19:34:19+00:00

I see no difference in sub classing the models.manager object and overriding the get_query_set

  • 0

I see no difference in sub classing the models.manager object and overriding the get_query_set method or simply creating a new method in the sub class and using the method. For the reason being I have taken example from the django book;

class MaleManager(models.Manager):
    def get_query_set(self):
        return super(MaleManager, self).get_query_set().filter(sex='M')
class FemaleManager(models.Manager):
    def get_query_set(self):
        return super(FemaleManager, self).get_query_set().filter(sex='F')
class Person(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F', 'Female')))
    people = models.Manager()
    men = MaleManager()
    women = FemaleManager()

With this I could use; Person.women.all() or Person.men.all() to fetch all the men or women model object. But, I guess the similar thing can be achieved without overriding the get_query_set method by simply doing;

class MaleManager(models.Manager):
    def get_male(self):
        return self.filter(sex='M')
class FemaleManager(models.Manager):
    def get_female(self):
        return  return self.filter(sex='F')
class Person(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F', 'Female')))
    people = models.Manager()
    men = MaleManager()
    women = FemaleManager()

Now, with this, I can fetch all those objects with a little technique like;
Person.objects.get_male() or Person.objects.get_female(). But, there’s no any subtle difference between how I could fetch the objects yet there is difference in terms of readability and use in first case while the second one is much easier to understand and has lesser code.Do they make some significant difference in coding and patterns ? The other thing with the second one, what if I place both the methods inside a same class like;

class PeopleManager(models.Manager):
        def get_male(self):
            return self.filter(sex='M')
        def get_female(self):
            return  return self.filter(sex='F')
  • 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-27T19:34:20+00:00Added an answer on May 27, 2026 at 7:34 pm
    1. Usually you don’t want several managers for the model. It’s better to extend default manager.

      class PeopleManager(models.Manager):
          def get_male(self):
              return self.filter(sex='M')
      
          def get_female(self):
              return  return self.filter(sex='F')
      
      class Person(models.Model):
          ....
          objects = PeopleManager()
      

      Then you will be able to use Person.objects.get_male(), Person.objects.get_female() and built-in methods like Person.objects.order_by(). You can look at custom managers in django.contrib.auth.models for example.

    2. get_query_set is good for inheritance. For example you can define

      class SmithManager(PeopleManager):
          def get_queryset(self):
              return super(SmithManager, self).get_query_set().filter(last_name='Smith')
      

      and all the methods of the manager will return only Smiths, (Person.objects.get_male() will return only males named Smith and so on). And you don’t need to rewrite all the methods.

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

Sidebar

Related Questions

I see little functional difference between using a property public readonly property foo as
Why do I see a difference when I convert a unix timestamp to datetime
I'm doing some tests, but I see no difference when I use or not
We see a size difference here when building our application in VC 2008 Express
What's the difference between @{property} and ${property} in accessing Ant properties? Didn't see any
I was creating a stored procedure and I see some differences between my methodology
Is am using this: SetWindowsHookEx(WH_CALLWNDPROC, ...); I can see the messages I want to
I don't know what real difference between two type of using when I want
I can see that GD library is for images. But I can't see differences
see also Differences between LINQ to Objects and LINQ to SQL queries We are

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.