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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:04:34+00:00 2026-06-11T04:04:34+00:00

Suppose we have multiple sites (using sites-framework of Django) running on the same django

  • 0

Suppose we have multiple sites (using sites-framework of Django) running on the same django instance.

MyModel.objects.filter(site_id=request.site, slug=slug)[0] might be an overhead in the future. So I was wondering if I could split the databases for this model(s) for querying faster.

So if request.site is 1, running

MyModel.objects.get(slug=slug)

will query only db1.

If request.site is 2, running

MyModel.objects.get(slug=slug)

will query only db2.

I will be getting request.site from the request parameter of the view as value of site will be dynamically determined according to the subdomain used: de, fr, etc.

  • 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-11T04:04:36+00:00Added an answer on June 11, 2026 at 4:04 am

    You may create a custom router to do this:

    Example:

    def get_current_site():
       SITE_ID = getattr(settings, 'SITE_ID', 1)
       site_name = Site.objects.get(id=SITE_ID)
       return site_name
    
    
    DATABASE_ROUTERS = ['CustomDatabaseRouter',] #a setting that Django understands.
    
    class CustomDatabaseRouter(object):
    
      def db_for_read(self, model, **hints):
         site_name = get_current_site()
         if site_name  in ['site1']:
             return 'db1'
         if site_name in ['site2']:
            return 'db2'
         return 'default'
    
      def db_for_write(self, model, **hints):
         site_name = get_current_site()
         if site_name  in ['site1']:
             return 'db1'
         if site_name in ['site2']:
            return 'db2'
         return 'default'
    
      def allow_syncdb(self, model, **hints):
         site_name = get_current_site()
         if site_name in ['site1'] and db == 'db1':
             return True
         if site_name in ['site2'] and db == 'db2':
            return True
         return False
    

    You can readup more here
    https://docs.djangoproject.com/en/dev/topics/db/multi-db/

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

Sidebar

Related Questions

In Windows, suppose you have multiple windows (HWNDs) of the same window class open.
so 1GvG:s/..../g can replace over an entire buffer However, suppose I have multiple vim
I have multiple Facebook like boxes in one page. Suppose, I have two dives
suppose i have a .on() function wherein i select multiple ids $(#i, #am, #your,
Suppose multiple Modal Windows shown above each other. All of those have ShowInTaskbar =
suppose I have www.usa.com as main site. I will create www.utah.com..www.indiana.com...etc on same dedicated
I'm supposed to build some Django apps, that allow you to administer multiple sites
Suppose you have a window with multiple buttons such as Ok/Cancel or Yes/No/Cancel. All
I have a Mule Application where I send a Request to Multiple WebServices and
Suppose I have multiple roles, each one defining a set of items: package A;

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.