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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:15:50+00:00 2026-06-08T09:15:50+00:00

I am having two models and a custom Manager: class ActiveModelAManager(models.Manager): def get_query_set(self): return

  • 0

I am having two models and a custom Manager:

class ActiveModelAManager(models.Manager):
    def get_query_set(self):
        return super(ActiveModelAManager,self).get_query_set().filter( active = True)

class ModelA(models.Model):
    name = CharField(....)
    active = BooleanField()

    active_models = ActiveModelAManager()
    objects = models.Manager()

class ModelB(models.Model):
    modelA = ForeignKey(ModelA)

in my view I am passing ModelA to the template and I would like to access ModelB_set but using my active_models manager instead of objects ?

so if I am doing this :

{{ ModelB.modelb_set.all }} 

I am accessing the objects manager but I want to access the active_models.
Same problem goes when I am trying to access the custom manager via my view.

Any idea how can I accomplish this ?

  • 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-08T09:15:53+00:00Added an answer on June 8, 2026 at 9:15 am

    Not sure whether I got your question right, but in order to query for the modelB objects which reference to an active ModelA object, in your view you can just write.

    active_modelA_objects = ModelA.active_models.all().values_list('pk', flat=True)
    modelB_objects_with_active_modelA = ModelB.objects.filter(modelA__in=active_modelA_objects)
    

    Related docs:

    values-list

    __in

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

Sidebar

Related Questions

I have two models with managers: Category and Project. class PopulatedCategoriesManager(models.Manager): def get_query_set(self): return
im having a two models one is companyusers and the other is qualification and
How do I go about having two view models communicate with one another using
I'm having a difficult time understanding how to do this. I have two models,
I have two models like this: class Store(models.Model): name = models.CharField(max_length=255) class Order(models.Model): store
I have two models class Status(models.Model) name = models.CharField(max_length=25) rank = models.PositiveSmallIntegerField() class MyModel(models.Model)
I'm having problems with my fixtures in Rails. I have two models, a message
I have two models in separate apps: # Groups app class Group(models.Model): name =
I'm having two models, the first one ( model_1 ) accepts nested attributes for
I have a model with two foreign keys: class Model1(models.Model): model_a = models.ForeignKey(ModelA) model_b

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.