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

  • Home
  • SEARCH
  • 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 8668525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:14:05+00:00 2026-06-12T18:14:05+00:00

I have a model which has an active field, and i want to filter

  • 0

I have a model which has an active field, and i want to filter out all records which are inactive basing on this field. Let’s say:

Record(Model):
    active = BooleanField()
    ...

to filter them out i can do:

Record.objects(active=True)

But it is a general case and i want inactive records to be filtered out almost any time. What is the best way to follow DRY principle and do not filter every request i do manually like in example above and in meantime keep the ability to manage inactive records in admin panel.

  • 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-12T18:14:06+00:00Added an answer on June 12, 2026 at 6:14 pm

    You can use Managers to achieve this task:

    # First, define the Manager subclass.
    class ActiveManager(models.Manager):
        def get_query_set(self):
            return super(ActiveManager, self).get_query_set().filter(active=True)
    
    # Then hook it into the Record model explicitly.
    class Record(models.Model):
        active = BooleanField()
    
        objects = models.Manager() # The default manager.
        active_objects = ActiveManager() # The specific manager.
    
    #to filter for all active records you can do:
    Record.active_objects.all()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model Foo which has field bar. The bar field should be unique,
In my model, let's call it questions, I have active field (TINYINT). The idea
I have an Active Record model object called Event, which has many event_things. I
I have an active form model which has fields I do not wish to
I have a model, Domain , which has a text field, names . >
Say you have an Active Record model which contains a set of records: id
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
I have a model which has a certain behaviour implemented. class X { ....
I'm using ASP.NET MVC and have a model which has an image (byte array)
I have an Entry model which has many Tag s. Tag s are added

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.