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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:37:55+00:00 2026-05-29T23:37:55+00:00

I’m just getting my hands on Django Managers and I’ve found myself doing this

  • 0

I’m just getting my hands on Django Managers and I’ve found myself doing this type of programming. I’m looking to see if there is a way to remove the obvious repetition.. I believe I need to define use get_query_set to refer to myself?

To be very clear on my question. I am repeatadly having to pass in the subdivision in order to figure out the rows from which to filter on. I think there is an easier way I’m just not sure what it is.

Thanks for looking!!

— models.py

class Subdivision(models.Model):
    objects = SubdivisionManager()

— managers.py

class SubdivisionManager(models.Manager):
    """A generic manager with metros"""


    def is_metro_sample_eligible(self, subdivision_id):
        """Are we eligible for sampling taking into account the 90 day windows"""
        from .models import Subdivision
        subdivision = Subdivision.objects.get(id=subdivision_id)
        return True


    def get_available_subdivisions(self, subdivision_id):
        """Return all potential subdivisions for a builder in a metro"""
        from .models import Subdivision
        subdivision = Subdivision.objects.get(id=subdivision_id)
        return self.filter(builder_org=subdivision.builder_org,
                           metro=subdivision.metro)

    def get_available_sampling_subdivisions(self, subdivision_id):
        """Return Subdivision which are able to participate in metro sampling"""
        from .models import Subdivision
        subdivision = Subdivision.objects.get(id=subdivision_id)
        return self.filter(builder_org=subdivision.builder_org,
                           metro=subdivision.metro,
                           use_sampling = True,
                           use_metro_sampling = True)
  • 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-29T23:37:56+00:00Added an answer on May 29, 2026 at 11:37 pm

    Actually, I’d put is_metro_sample_eligible() on Subdivision, since each call needs to access an instance.

    class Subdivision(models.Model):
        def is_metro_sample_eligible(self):
            """Are we eligible for sampling taking into account the 90 day windows"""
            #TODO do something useful here and return true or false
            return True
    

    And then I’d either move get_available_subdivisions() and get_available_sampling_subdivisions() onto your builder_org model

    from .models import Subdivision
    
    class BuilderOrg(models.Model):
        #whatever you have goes here
        def get_available_subdivisions(self, metro):
            """Return all potential subdivisions for a builder in a metro"""
            return Subdivision.objects.filter(builder_org=self,
                                              metro=metro)
    
        def get_available_sampling_subdivisions(self, metro):
            """Return Subdivision which are able to participate in metro sampling"""
            return Subdivision.objects.filter(builder_org=self,
                                              metro=metro,
                                              use_sampling = True,
                                              use_metro_sampling = True)
    

    or leave it on the manager, and revise the signature to get_available_subdivisions(self, builder_org, metro).

    Rationale- I could imagine needing to call get_available_subdivisions() without actually having a Subdivision already in mind- clearly the important pieces of information are the builder organization and the metro.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.