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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:25:03+00:00 2026-06-04T05:25:03+00:00

I run a site that operates the same on many URLs except for the

  • 0

I run a site that operates the same on many URLs except for the name and the display of objects tied to a given site. Because of this I have extended the Site model to include various other bits of information about a site and created a middleware to put the standard Site object information into the request object. Previously the only info I needed in the request object was the site’s name, which I could get from the Site models Django provides. I now need bits of information that reside in my extended Site model (which previously was only used by my other various app models).

This goes from adding one query to each page (request.site = Site.objects.get_current()) to adding two, as I need to get the current site, then get the associated extended Site object from my model.

Is there a way to get this information without using two queries? Or even without using one?

models.py:

from django.contrib.sites.models import Site

class SiteMethods(Site):
    """
    Extended site model
    """
    colloquial_name = models.CharField(max_length=32,)
    ...

middleware.py:

class RequestContextMiddleware(object):
    """
    Puts the Site into each request object
    """
    def process_request(self, request):
        # This runs two queries on every page, instead of just one
        request.site = SiteMethods.objects.get(id=Site.objects.get_current().id)
        return None

In my settings.py file, I have all shared configuration data. My server instances (gunicorn) are configured to load [site]_settings.py, which holds all site-specific settings (to include Django’s SITE_ID), and at the bottom:

try:
    from settings import *
except ImportError:
    pass

I am looking for options (if they exist) that do not include referencing the hard-coded SITE_ID in [site]_settings.py.

Update:

As suggested below, subclassed objects should still have access to their parent objects and all the parent object’s functionality. For the Site object, strangely, this seems to not be the case.

>>> Site.objects.get_current()
<Site: website.com>
>>> SiteMethods.objects.get_current()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'Manager' object has no attribute 'get_current'
>>> SiteMethods.objects.select_related('site').get_current() # as suggested below
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'QuerySet' object has no attribute 'get_current'
>>> dir(SiteMethods)
['DoesNotExist', 'MultipleObjectsReturned', '__class__', '__delattr__', '__dict__',
'__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', 
'__metaclass__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', 
'__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', 
'__weakref__', '_base_manager', '_default_manager', '_deferred', '_get_FIELD_display', 
'_get_next_or_previous_by_FIELD', '_get_next_or_previous_in_order', '_get_pk_val', 
'_get_unique_checks', '_meta', '_perform_date_checks', '_perform_unique_checks', 
'_set_pk_val', 'clean', 'clean_fields', 'date_error_message', 'delete', 'full_clean', 
'objects', 'pk', 'prepare_database_save', 'save', 'save_base', 'serializable_value', 
'site_ptr', 'sitemethods', 'unique_error_message', 'validate_unique',]
  • 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-04T05:25:04+00:00Added an answer on June 4, 2026 at 5:25 am

    Since you subclassed Site you should be able to just do SiteMethods.objects.get_current(), which will net you an instance of SiteMethods. Since Django’s implementation of MTI (Multiple Table Inheritance) uses a OneToOneField to the parent class, you should also be able to use select_related for site. So, try the following:

    SiteMethods.objects.select_related('site').get_current()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I run a site where it is important to have good and simple URLs
Since the app id is depending on the site name, how can i run
So the site I'm working on has a filter system that operates by passing
I run a site that is slowly but surely draining all of the available
I am developing an auction site that requires maintenance scripts to be run in
I have a directory on my site that I've implemented PEAR's Auth to run
If you run a site that links to world of warcraft items, you're probably
I'm developing a site that will run from Heroku and I'm about to the
I've inherited a php4 site that needs to run on my PHP5 Server, I've
I have a magnet link from a torrent site that should open this program

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.